From b4cc2347e547b1bc0900e99a80a236292333cc58 Mon Sep 17 00:00:00 2001 From: Rogee Date: Fri, 23 May 2025 22:59:18 +0800 Subject: [PATCH] feat: update --- pkg/ast/model/provider.gen.go.tpl | 8 ++++++++ pkg/ast/model/table_funcs.go.tpl | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/ast/model/provider.gen.go.tpl b/pkg/ast/model/provider.gen.go.tpl index 6699cdb..f242fb0 100644 --- a/pkg/ast/model/provider.gen.go.tpl +++ b/pkg/ast/model/provider.gen.go.tpl @@ -10,8 +10,16 @@ import ( "go.ipao.vip/atom/container" "go.ipao.vip/atom/contracts" "go.ipao.vip/atom/opt" + . "github.com/go-jet/jet/v2/postgres" ) +type Cond func(BoolExpression) BoolExpression + +func CondDefault() BoolExpression { + return BoolExp(Bool(true)) +} + + var db *sql.DB {{- range . }} func {{.PascalTable}}Model() *{{.PascalTable}} { return &{{.PascalTable}}{} } diff --git a/pkg/ast/model/table_funcs.go.tpl b/pkg/ast/model/table_funcs.go.tpl index 894b61d..cd038d3 100644 --- a/pkg/ast/model/table_funcs.go.tpl +++ b/pkg/ast/model/table_funcs.go.tpl @@ -10,8 +10,18 @@ import ( . "github.com/go-jet/jet/v2/postgres" log "github.com/sirupsen/logrus" ) +// conds +{{- if .SoftDelete }} +func (m *{{.PascalTable}}) NotDeleted() Cond { + return func(cond BoolExpression) BoolExpression { + return cond.AND(table.Posts.DeletedAt.IS_NULL()) + } +} +{{- end}} + +// funcs func (m *{{.PascalTable}}) log() *log.Entry { return log.WithField("model", "{{.PascalTable}}") } @@ -52,7 +62,6 @@ func (m *{{.PascalTable}}) BatchCreate(ctx context.Context, models []*{{.PascalT return nil } -// if SoftDelete {{- if .SoftDelete }} func (m *{{.PascalTable}}) Delete(ctx context.Context) error { stmt := table.{{.PascalTable}}.UPDATE().SET(table.{{.PascalTable}}.DeletedAt.Set(TimestampzT(time.Now()))).WHERE(table.{{.PascalTable}}.ID.EQ(Int(m.ID)))