96 lines
2.1 KiB
Smarty
96 lines
2.1 KiB
Smarty
// Code generated by the atomctl ; DO NOT EDIT.
|
|
// Code generated by the atomctl ; DO NOT EDIT.
|
|
// Code generated by the atomctl ; DO NOT EDIT.
|
|
package model
|
|
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"
|
|
"go.ipao.vip/atom/opt"
|
|
. "github.com/go-jet/jet/v2/postgres"
|
|
"github.com/samber/lo"
|
|
"golang.org/x/exp/constraints"
|
|
)
|
|
|
|
type Cond func(BoolExpression) BoolExpression
|
|
|
|
func ExprCond(expr BoolExpression) Cond {
|
|
return func(cond BoolExpression) BoolExpression {
|
|
return cond.AND(expr)
|
|
}
|
|
}
|
|
|
|
func CondTrue(conds ...Cond) BoolExpression {
|
|
cond:= BoolExp(Bool(true))
|
|
for _, c := range conds {
|
|
cond = c(cond)
|
|
}
|
|
return cond
|
|
}
|
|
|
|
func CondJoin(cond Cond, conds ...Cond) []Cond {
|
|
return append([]Cond{cond}, conds...)
|
|
}
|
|
|
|
// converts
|
|
func IntExprSlice[T constraints.Integer](slice []T) []Expression {
|
|
if len(slice) == 0 { return nil }
|
|
|
|
return lo.Map(slice, func(item T, _ int) Expression {
|
|
switch any(item).(type) {
|
|
case int8:
|
|
return Int8(int8(item))
|
|
case int16:
|
|
return Int16(int16(item))
|
|
case int32:
|
|
return Int32(int32(item))
|
|
case int64:
|
|
return Int64(int64(item))
|
|
case uint8:
|
|
return Uint8(uint8(item))
|
|
case uint16:
|
|
return Uint16(uint16(item))
|
|
case uint32:
|
|
return Uint32(uint32(item))
|
|
case uint64:
|
|
return Uint64(uint64(item))
|
|
default:
|
|
return nil
|
|
}
|
|
})
|
|
}
|
|
|
|
// tables
|
|
{{- range . }}
|
|
var tbl{{.PascalTable}} = table.{{.PascalTable}}
|
|
{{- end }}
|
|
|
|
|
|
// models
|
|
var db *sql.DB
|
|
{{- range . }}
|
|
func {{.PascalTable}}Model() *{{.PascalTable}} { return &{{.PascalTable}}{} }
|
|
{{- end }}
|
|
|
|
func Transaction(ctx context.Context) (*sql.Tx, error) { return db.Begin() }
|
|
|
|
func DB() *sql.DB { return db }
|
|
|
|
func Provide(opts ...opt.Option) error {
|
|
if err := container.Container.Provide(func( _db *sql.DB,) (contracts.Initial, error) {
|
|
db = _db
|
|
return nil, nil
|
|
}, atom.GroupInitial); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|