diff --git a/pkg/ast/model/provider.gen.go.tpl b/pkg/ast/model/provider.gen.go.tpl index 8c072d7..8dc3746 100644 --- a/pkg/ast/model/provider.gen.go.tpl +++ b/pkg/ast/model/provider.gen.go.tpl @@ -6,6 +6,11 @@ import ( "context" "database/sql" + + {{ if gt (len .) 0 }} + "{{ (index . 0).PkgName }}/database/table" + {{ end }} + "go.ipao.vip/atom" "go.ipao.vip/atom/container" "go.ipao.vip/atom/contracts" @@ -33,7 +38,13 @@ func CondJoin(cond Cond, conds ...Cond) []Cond { return append([]Cond{cond}, conds...) } +// tables +{{- range . }} +var tbl{{.PascalTable}} = table.{{.PascalTable}} +{{- end }} + +// models 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 08a5603..9534d4a 100644 --- a/pkg/ast/model/table_funcs.go.tpl +++ b/pkg/ast/model/table_funcs.go.tpl @@ -130,22 +130,22 @@ func (m *{{.PascalTable}}) BatchForceDelete(ctx context.Context, ids []int64) er return nil } -func (m *{{.PascalTable}}) Update(ctx context.Context) error { - {{- if .HasUpdatedAt}} - m.UpdatedAt = time.Now() - {{- end}} +// func (m *{{.PascalTable}}) Update(ctx context.Context) error { +// {{- if .HasUpdatedAt}} +// m.UpdatedAt = time.Now() +// {{- end}} - stmt := table.{{.PascalTable}}.UPDATE(table.{{.PascalTable}}.MutableColumns.Except({{.CamelTable}}UpdateExcludeColumns...)).SET(m).WHERE(table.{{.PascalTable}}.ID.EQ(Int(m.ID))).RETURNING(table.{{.PascalTable}}.AllColumns) - m.log().WithField("func", "Update").Info(stmt.DebugSql()) +// stmt := table.{{.PascalTable}}.UPDATE(table.{{.PascalTable}}.MutableColumns.Except({{.CamelTable}}UpdateExcludeColumns...)).SET(m).WHERE(table.{{.PascalTable}}.ID.EQ(Int(m.ID))).RETURNING(table.{{.PascalTable}}.AllColumns) +// m.log().WithField("func", "Update").Info(stmt.DebugSql()) - if err := stmt.QueryContext(ctx, db, m); err != nil { - m.log().WithField("func","Update").Errorf("error updating {{.PascalTable}} item: %v", err) - return err - } +// if err := stmt.QueryContext(ctx, db, m); err != nil { +// m.log().WithField("func","Update").Errorf("error updating {{.PascalTable}} item: %v", err) +// return err +// } - m.log().WithField("func", "Update").Infof("{{.PascalTable}} item updated successfully") - return nil -} +// m.log().WithField("func", "Update").Infof("{{.PascalTable}} item updated successfully") +// return nil +// } // GetByCond func (m *{{.PascalTable}}) GetByCond(ctx context.Context, conds ...Cond) (*{{.PascalTable}}, error) {