feat: update
This commit is contained in:
@@ -10,8 +10,16 @@ import (
|
|||||||
"go.ipao.vip/atom/container"
|
"go.ipao.vip/atom/container"
|
||||||
"go.ipao.vip/atom/contracts"
|
"go.ipao.vip/atom/contracts"
|
||||||
"go.ipao.vip/atom/opt"
|
"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
|
var db *sql.DB
|
||||||
{{- range . }}
|
{{- range . }}
|
||||||
func {{.PascalTable}}Model() *{{.PascalTable}} { return &{{.PascalTable}}{} }
|
func {{.PascalTable}}Model() *{{.PascalTable}} { return &{{.PascalTable}}{} }
|
||||||
|
|||||||
@@ -10,8 +10,18 @@ import (
|
|||||||
. "github.com/go-jet/jet/v2/postgres"
|
. "github.com/go-jet/jet/v2/postgres"
|
||||||
log "github.com/sirupsen/logrus"
|
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 {
|
func (m *{{.PascalTable}}) log() *log.Entry {
|
||||||
return log.WithField("model", "{{.PascalTable}}")
|
return log.WithField("model", "{{.PascalTable}}")
|
||||||
}
|
}
|
||||||
@@ -52,7 +62,6 @@ func (m *{{.PascalTable}}) BatchCreate(ctx context.Context, models []*{{.PascalT
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// if SoftDelete
|
|
||||||
{{- if .SoftDelete }}
|
{{- if .SoftDelete }}
|
||||||
func (m *{{.PascalTable}}) Delete(ctx context.Context) error {
|
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)))
|
stmt := table.{{.PascalTable}}.UPDATE().SET(table.{{.PascalTable}}.DeletedAt.Set(TimestampzT(time.Now()))).WHERE(table.{{.PascalTable}}.ID.EQ(Int(m.ID)))
|
||||||
|
|||||||
Reference in New Issue
Block a user