feat: update

This commit is contained in:
yanghao05
2025-05-23 22:45:36 +08:00
parent 9ddea39084
commit e5000bcc73
2 changed files with 14 additions and 3 deletions

View File

@@ -1,5 +1,10 @@
package model package model
var {{.CamelTable}}UpdateExcludeColumns = []Column{ var {{.CamelTable}}UpdateExcludeColumns = []Column{
// table.{{.PascalTable}}.CreatedAt, {{-if .HasCreatedAt}}
table.{{.PascalTable}}.CreatedAt,
{{- end}}
{{-if .SoftDelete}}
table.{{.PascalTable}}.DeletedAt,
{{- end}}
} }

View File

@@ -134,8 +134,14 @@ func (m *{{.PascalTable}}) Update(ctx context.Context) error {
return nil return nil
} }
// GetByID // GetByID
func (m *{{.PascalTable}}) GetByID(ctx context.Context, id int64) (*{{.PascalTable}}, error) { func (m *{{.PascalTable}}) GetByID(ctx context.Context, id int64, conds ...BoolExpression) (*{{.PascalTable}}, error) {
stmt := table.{{.PascalTable}}.SELECT(table.{{.PascalTable}}.AllColumns).WHERE(table.{{.PascalTable}}.ID.EQ(Int(m.ID))) 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()) m.log().WithField("func", "GetByID").Info(stmt.DebugSql())
if err := stmt.QueryContext(ctx, db, m); err != nil { if err := stmt.QueryContext(ctx, db, m); err != nil {