From e5000bcc734fc94cd8a227cd7e0151ef56dafc93 Mon Sep 17 00:00:00 2001 From: yanghao05 Date: Fri, 23 May 2025 22:45:36 +0800 Subject: [PATCH] feat: update --- pkg/ast/model/table.go.tpl | 7 ++++++- pkg/ast/model/table_funcs.go.tpl | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/ast/model/table.go.tpl b/pkg/ast/model/table.go.tpl index 5b50ae2..f51aa9c 100644 --- a/pkg/ast/model/table.go.tpl +++ b/pkg/ast/model/table.go.tpl @@ -1,5 +1,10 @@ package model var {{.CamelTable}}UpdateExcludeColumns = []Column{ - // table.{{.PascalTable}}.CreatedAt, + {{-if .HasCreatedAt}} + table.{{.PascalTable}}.CreatedAt, + {{- end}} + {{-if .SoftDelete}} + table.{{.PascalTable}}.DeletedAt, + {{- end}} } diff --git a/pkg/ast/model/table_funcs.go.tpl b/pkg/ast/model/table_funcs.go.tpl index 1a401ad..0fcca58 100644 --- a/pkg/ast/model/table_funcs.go.tpl +++ b/pkg/ast/model/table_funcs.go.tpl @@ -134,8 +134,14 @@ func (m *{{.PascalTable}}) Update(ctx context.Context) error { return nil } // GetByID -func (m *{{.PascalTable}}) GetByID(ctx context.Context, id int64) (*{{.PascalTable}}, error) { - stmt := table.{{.PascalTable}}.SELECT(table.{{.PascalTable}}.AllColumns).WHERE(table.{{.PascalTable}}.ID.EQ(Int(m.ID))) +func (m *{{.PascalTable}}) GetByID(ctx context.Context, id int64, conds ...BoolExpression) (*{{.PascalTable}}, error) { + expr := table.{{.PascalTable}}.ID.EQ(Int(m.ID)) + if len(conds) > 0 { + for _, c := range conds { + expr = expr.AND(c) + } + } + stmt := table.{{.PascalTable}}.SELECT(table.{{.PascalTable}}.AllColumns).WHERE() m.log().WithField("func", "GetByID").Info(stmt.DebugSql()) if err := stmt.QueryContext(ctx, db, m); err != nil {