100 lines
2.1 KiB
Go
100 lines
2.1 KiB
Go
// 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"
|
|
|
|
"quyun/database/table"
|
|
|
|
. "github.com/go-jet/jet/v2/postgres"
|
|
"github.com/samber/lo"
|
|
"go.ipao.vip/atom"
|
|
"go.ipao.vip/atom/container"
|
|
"go.ipao.vip/atom/contracts"
|
|
"go.ipao.vip/atom/opt"
|
|
"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
|
|
var tblMedias = table.Medias
|
|
var tblOrders = table.Orders
|
|
var tblPosts = table.Posts
|
|
var tblUserPosts = table.UserPosts
|
|
var tblUsers = table.Users
|
|
|
|
// models
|
|
var db *sql.DB
|
|
|
|
func MediasModel() *Medias { return &Medias{} }
|
|
func OrdersModel() *Orders { return &Orders{} }
|
|
func PostsModel() *Posts { return &Posts{} }
|
|
func UserPostsModel() *UserPosts { return &UserPosts{} }
|
|
func UsersModel() *Users { return &Users{} }
|
|
|
|
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
|
|
}
|