feat: update
This commit is contained in:
@@ -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}}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user