del: clean template
This commit is contained in:
@@ -1,891 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newCustomer(db *gorm.DB, opts ...gen.DOOption) customer {
|
||||
_customer := customer{}
|
||||
|
||||
_customer.customerDo.UseDB(db, opts...)
|
||||
_customer.customerDo.UseModel(&models.Customer{})
|
||||
|
||||
tableName := _customer.customerDo.TableName()
|
||||
_customer.ALL = field.NewAsterisk(tableName)
|
||||
_customer.Id = field.NewUint(tableName, "id")
|
||||
_customer.Title = field.NewString(tableName, "title")
|
||||
_customer.Contact = field.NewString(tableName, "contact")
|
||||
_customer.Orders = customerHasManyOrders{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Orders", "models.Order"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.ProductType", "models.ProductType"),
|
||||
},
|
||||
Customer: struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Customer", "models.Customer"),
|
||||
Orders: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Customer.Orders", "models.Order"),
|
||||
},
|
||||
},
|
||||
Tasks: struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Order struct {
|
||||
field.RelationField
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
WorkAreas struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workers struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
Shifts struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Workshops struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks", "models.Task"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.ProductType", "models.ProductType"),
|
||||
},
|
||||
Order: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.Order", "models.Order"),
|
||||
},
|
||||
PrepTasks: struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
WorkAreas struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workers struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
Shifts struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks", "models.PrepTask"),
|
||||
Task: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.Task", "models.Task"),
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
WorkAreas struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workers struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
Shifts struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea", "models.WorkArea"),
|
||||
Workshop: struct {
|
||||
field.RelationField
|
||||
WorkAreas struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workers struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.Workshop", "models.Workshop"),
|
||||
WorkAreas: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.Workshop.WorkAreas", "models.WorkArea"),
|
||||
},
|
||||
Workers: struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.Workshop.Workers", "models.Worker"),
|
||||
Workshop: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.Workshop.Workers.Workshop", "models.Workshop"),
|
||||
},
|
||||
TeamTasks: struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.Workshop.Workers.TeamTasks", "models.TeamTask"),
|
||||
TeamType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.Workshop.Workers.TeamTasks.TeamType", "models.TeamType"),
|
||||
},
|
||||
TeamLeader: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.Workshop.Workers.TeamTasks.TeamLeader", "models.Worker"),
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.Workshop.Workers.TeamTasks.WorkArea", "models.WorkArea"),
|
||||
},
|
||||
TeamMembers: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.Workshop.Workers.TeamTasks.TeamMembers", "models.Worker"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Tasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.Workshop.Tasks", "models.Task"),
|
||||
},
|
||||
},
|
||||
PrepTasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.PrepTasks", "models.PrepTask"),
|
||||
},
|
||||
Shifts: struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.Shifts", "models.Shift"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.Shifts.ProductType", "models.ProductType"),
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.Shifts.WorkArea", "models.WorkArea"),
|
||||
},
|
||||
},
|
||||
TeamTasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.PrepTasks.WorkArea.TeamTasks", "models.TeamTask"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Workshops: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Orders.Tasks.Workshops", "models.Workshop"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
_customer.fillFieldMap()
|
||||
|
||||
return _customer
|
||||
}
|
||||
|
||||
type customer struct {
|
||||
customerDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
Title field.String
|
||||
Contact field.String
|
||||
Orders customerHasManyOrders
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (c customer) Table(newTableName string) *customer {
|
||||
c.customerDo.UseTable(newTableName)
|
||||
return c.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (c customer) As(alias string) *customer {
|
||||
c.customerDo.DO = *(c.customerDo.As(alias).(*gen.DO))
|
||||
return c.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (c *customer) updateTableName(table string) *customer {
|
||||
c.ALL = field.NewAsterisk(table)
|
||||
c.Id = field.NewUint(table, "id")
|
||||
c.Title = field.NewString(table, "title")
|
||||
c.Contact = field.NewString(table, "contact")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *customer) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := c.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (c *customer) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 4)
|
||||
c.fieldMap["id"] = c.Id
|
||||
c.fieldMap["title"] = c.Title
|
||||
c.fieldMap["contact"] = c.Contact
|
||||
|
||||
}
|
||||
|
||||
func (c customer) clone(db *gorm.DB) customer {
|
||||
c.customerDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c customer) replaceDB(db *gorm.DB) customer {
|
||||
c.customerDo.ReplaceDB(db)
|
||||
return c
|
||||
}
|
||||
|
||||
type customerHasManyOrders struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Order struct {
|
||||
field.RelationField
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
WorkAreas struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workers struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
Shifts struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Workshops struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a customerHasManyOrders) Where(conds ...field.Expr) *customerHasManyOrders {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a customerHasManyOrders) WithContext(ctx context.Context) *customerHasManyOrders {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a customerHasManyOrders) Session(session *gorm.Session) *customerHasManyOrders {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a customerHasManyOrders) Model(m *models.Customer) *customerHasManyOrdersTx {
|
||||
return &customerHasManyOrdersTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type customerHasManyOrdersTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a customerHasManyOrdersTx) Find() (result []*models.Order, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a customerHasManyOrdersTx) Append(values ...*models.Order) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a customerHasManyOrdersTx) Replace(values ...*models.Order) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a customerHasManyOrdersTx) Delete(values ...*models.Order) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a customerHasManyOrdersTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a customerHasManyOrdersTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type customerDo struct{ gen.DO }
|
||||
|
||||
type ICustomerDo interface {
|
||||
gen.SubQuery
|
||||
Debug() ICustomerDo
|
||||
WithContext(ctx context.Context) ICustomerDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() ICustomerDo
|
||||
WriteDB() ICustomerDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) ICustomerDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) ICustomerDo
|
||||
Not(conds ...gen.Condition) ICustomerDo
|
||||
Or(conds ...gen.Condition) ICustomerDo
|
||||
Select(conds ...field.Expr) ICustomerDo
|
||||
Where(conds ...gen.Condition) ICustomerDo
|
||||
Order(conds ...field.Expr) ICustomerDo
|
||||
Distinct(cols ...field.Expr) ICustomerDo
|
||||
Omit(cols ...field.Expr) ICustomerDo
|
||||
Join(table schema.Tabler, on ...field.Expr) ICustomerDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) ICustomerDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) ICustomerDo
|
||||
Group(cols ...field.Expr) ICustomerDo
|
||||
Having(conds ...gen.Condition) ICustomerDo
|
||||
Limit(limit int) ICustomerDo
|
||||
Offset(offset int) ICustomerDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) ICustomerDo
|
||||
Unscoped() ICustomerDo
|
||||
Create(values ...*models.Customer) error
|
||||
CreateInBatches(values []*models.Customer, batchSize int) error
|
||||
Save(values ...*models.Customer) error
|
||||
First() (*models.Customer, error)
|
||||
Take() (*models.Customer, error)
|
||||
Last() (*models.Customer, error)
|
||||
Find() ([]*models.Customer, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Customer, err error)
|
||||
FindInBatches(result *[]*models.Customer, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*models.Customer) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) ICustomerDo
|
||||
Assign(attrs ...field.AssignExpr) ICustomerDo
|
||||
Joins(fields ...field.RelationField) ICustomerDo
|
||||
Preload(fields ...field.RelationField) ICustomerDo
|
||||
FirstOrInit() (*models.Customer, error)
|
||||
FirstOrCreate() (*models.Customer, error)
|
||||
FindByPage(offset int, limit int) (result []*models.Customer, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) ICustomerDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (c customerDo) Debug() ICustomerDo {
|
||||
return c.withDO(c.DO.Debug())
|
||||
}
|
||||
|
||||
func (c customerDo) WithContext(ctx context.Context) ICustomerDo {
|
||||
return c.withDO(c.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (c customerDo) ReadDB() ICustomerDo {
|
||||
return c.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (c customerDo) WriteDB() ICustomerDo {
|
||||
return c.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (c customerDo) Session(config *gorm.Session) ICustomerDo {
|
||||
return c.withDO(c.DO.Session(config))
|
||||
}
|
||||
|
||||
func (c customerDo) Clauses(conds ...clause.Expression) ICustomerDo {
|
||||
return c.withDO(c.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (c customerDo) Returning(value interface{}, columns ...string) ICustomerDo {
|
||||
return c.withDO(c.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (c customerDo) Not(conds ...gen.Condition) ICustomerDo {
|
||||
return c.withDO(c.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (c customerDo) Or(conds ...gen.Condition) ICustomerDo {
|
||||
return c.withDO(c.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (c customerDo) Select(conds ...field.Expr) ICustomerDo {
|
||||
return c.withDO(c.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (c customerDo) Where(conds ...gen.Condition) ICustomerDo {
|
||||
return c.withDO(c.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (c customerDo) Order(conds ...field.Expr) ICustomerDo {
|
||||
return c.withDO(c.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (c customerDo) Distinct(cols ...field.Expr) ICustomerDo {
|
||||
return c.withDO(c.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (c customerDo) Omit(cols ...field.Expr) ICustomerDo {
|
||||
return c.withDO(c.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (c customerDo) Join(table schema.Tabler, on ...field.Expr) ICustomerDo {
|
||||
return c.withDO(c.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (c customerDo) LeftJoin(table schema.Tabler, on ...field.Expr) ICustomerDo {
|
||||
return c.withDO(c.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c customerDo) RightJoin(table schema.Tabler, on ...field.Expr) ICustomerDo {
|
||||
return c.withDO(c.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c customerDo) Group(cols ...field.Expr) ICustomerDo {
|
||||
return c.withDO(c.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (c customerDo) Having(conds ...gen.Condition) ICustomerDo {
|
||||
return c.withDO(c.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (c customerDo) Limit(limit int) ICustomerDo {
|
||||
return c.withDO(c.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (c customerDo) Offset(offset int) ICustomerDo {
|
||||
return c.withDO(c.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (c customerDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ICustomerDo {
|
||||
return c.withDO(c.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (c customerDo) Unscoped() ICustomerDo {
|
||||
return c.withDO(c.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (c customerDo) Create(values ...*models.Customer) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Create(values)
|
||||
}
|
||||
|
||||
func (c customerDo) CreateInBatches(values []*models.Customer, batchSize int) error {
|
||||
return c.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (c customerDo) Save(values ...*models.Customer) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Save(values)
|
||||
}
|
||||
|
||||
func (c customerDo) First() (*models.Customer, error) {
|
||||
if result, err := c.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Customer), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c customerDo) Take() (*models.Customer, error) {
|
||||
if result, err := c.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Customer), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c customerDo) Last() (*models.Customer, error) {
|
||||
if result, err := c.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Customer), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c customerDo) Find() ([]*models.Customer, error) {
|
||||
result, err := c.DO.Find()
|
||||
return result.([]*models.Customer), err
|
||||
}
|
||||
|
||||
func (c customerDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Customer, err error) {
|
||||
buf := make([]*models.Customer, 0, batchSize)
|
||||
err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (c customerDo) FindInBatches(result *[]*models.Customer, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return c.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (c customerDo) Attrs(attrs ...field.AssignExpr) ICustomerDo {
|
||||
return c.withDO(c.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (c customerDo) Assign(attrs ...field.AssignExpr) ICustomerDo {
|
||||
return c.withDO(c.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (c customerDo) Joins(fields ...field.RelationField) ICustomerDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Joins(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c customerDo) Preload(fields ...field.RelationField) ICustomerDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Preload(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c customerDo) FirstOrInit() (*models.Customer, error) {
|
||||
if result, err := c.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Customer), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c customerDo) FirstOrCreate() (*models.Customer, error) {
|
||||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Customer), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c customerDo) FindByPage(offset int, limit int) (result []*models.Customer, count int64, err error) {
|
||||
result, err = c.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = c.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (c customerDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = c.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = c.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (c customerDo) Scan(result interface{}) (err error) {
|
||||
return c.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (c customerDo) Delete(models ...*models.Customer) (result gen.ResultInfo, err error) {
|
||||
return c.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (c *customerDo) withDO(do gen.Dao) *customerDo {
|
||||
c.DO = *do.(*gen.DO)
|
||||
return c
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func init() {
|
||||
InitializeDB()
|
||||
err := _gen_test_db.AutoMigrate(&models.Customer{})
|
||||
if err != nil {
|
||||
fmt.Printf("Error: AutoMigrate(&models.Customer{}) fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_customerQuery(t *testing.T) {
|
||||
customer := newCustomer(_gen_test_db)
|
||||
customer = *customer.As(customer.TableName())
|
||||
_do := customer.WithContext(context.Background()).Debug()
|
||||
|
||||
primaryKey := field.NewString(customer.TableName(), clause.PrimaryKey)
|
||||
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
|
||||
if err != nil {
|
||||
t.Error("clean table <customers> fail:", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, ok := customer.GetFieldByName("")
|
||||
if ok {
|
||||
t.Error("GetFieldByName(\"\") from customer success")
|
||||
}
|
||||
|
||||
err = _do.Create(&models.Customer{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <customers> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Save(&models.Customer{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <customers> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.CreateInBatches([]*models.Customer{{}, {}}, 10)
|
||||
if err != nil {
|
||||
t.Error("create item in table <customers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(customer.ALL).Take()
|
||||
if err != nil {
|
||||
t.Error("Take() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.First()
|
||||
if err != nil {
|
||||
t.Error("First() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Last()
|
||||
if err != nil {
|
||||
t.Error("First() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatch() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*models.Customer{}, 10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatches() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(customer.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
|
||||
if err != nil {
|
||||
t.Error("Find() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Distinct(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("select Distinct() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(customer.ALL).Omit(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("Omit() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Group(primaryKey).Find()
|
||||
if err != nil {
|
||||
t.Error("Group() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
|
||||
if err != nil {
|
||||
t.Error("Scopes() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
_, _, err = _do.FindByPage(0, 1)
|
||||
if err != nil {
|
||||
t.Error("FindByPage() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.ScanByPage(&models.Customer{}, 0, 1)
|
||||
if err != nil {
|
||||
t.Error("ScanByPage() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
|
||||
if err != nil {
|
||||
t.Error("FirstOrInit() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
|
||||
if err != nil {
|
||||
t.Error("FirstOrCreate() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
var _a _another
|
||||
var _aPK = field.NewString(_a.TableName(), "id")
|
||||
|
||||
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("Join() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("LeftJoin() on table <customers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Not().Or().Clauses().Take()
|
||||
if err != nil {
|
||||
t.Error("Not/Or/Clauses on table <customers> fail:", err)
|
||||
}
|
||||
}
|
||||
@@ -16,84 +16,34 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
Q = new(Query)
|
||||
Customer *customer
|
||||
Order *order
|
||||
PrepTask *prepTask
|
||||
ProductType *productType
|
||||
Shift *shift
|
||||
Task *task
|
||||
TeamTask *teamTask
|
||||
TeamType *teamType
|
||||
WorkArea *workArea
|
||||
Worker *worker
|
||||
Workshop *workshop
|
||||
Q = new(Query)
|
||||
Post *post
|
||||
)
|
||||
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
*Q = *Use(db, opts...)
|
||||
Customer = &Q.Customer
|
||||
Order = &Q.Order
|
||||
PrepTask = &Q.PrepTask
|
||||
ProductType = &Q.ProductType
|
||||
Shift = &Q.Shift
|
||||
Task = &Q.Task
|
||||
TeamTask = &Q.TeamTask
|
||||
TeamType = &Q.TeamType
|
||||
WorkArea = &Q.WorkArea
|
||||
Worker = &Q.Worker
|
||||
Workshop = &Q.Workshop
|
||||
Post = &Q.Post
|
||||
}
|
||||
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Customer: newCustomer(db, opts...),
|
||||
Order: newOrder(db, opts...),
|
||||
PrepTask: newPrepTask(db, opts...),
|
||||
ProductType: newProductType(db, opts...),
|
||||
Shift: newShift(db, opts...),
|
||||
Task: newTask(db, opts...),
|
||||
TeamTask: newTeamTask(db, opts...),
|
||||
TeamType: newTeamType(db, opts...),
|
||||
WorkArea: newWorkArea(db, opts...),
|
||||
Worker: newWorker(db, opts...),
|
||||
Workshop: newWorkshop(db, opts...),
|
||||
db: db,
|
||||
Post: newPost(db, opts...),
|
||||
}
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
Customer customer
|
||||
Order order
|
||||
PrepTask prepTask
|
||||
ProductType productType
|
||||
Shift shift
|
||||
Task task
|
||||
TeamTask teamTask
|
||||
TeamType teamType
|
||||
WorkArea workArea
|
||||
Worker worker
|
||||
Workshop workshop
|
||||
Post post
|
||||
}
|
||||
|
||||
func (q *Query) Available() bool { return q.db != nil }
|
||||
|
||||
func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Customer: q.Customer.clone(db),
|
||||
Order: q.Order.clone(db),
|
||||
PrepTask: q.PrepTask.clone(db),
|
||||
ProductType: q.ProductType.clone(db),
|
||||
Shift: q.Shift.clone(db),
|
||||
Task: q.Task.clone(db),
|
||||
TeamTask: q.TeamTask.clone(db),
|
||||
TeamType: q.TeamType.clone(db),
|
||||
WorkArea: q.WorkArea.clone(db),
|
||||
Worker: q.Worker.clone(db),
|
||||
Workshop: q.Workshop.clone(db),
|
||||
db: db,
|
||||
Post: q.Post.clone(db),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,48 +57,18 @@ func (q *Query) WriteDB() *Query {
|
||||
|
||||
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Customer: q.Customer.replaceDB(db),
|
||||
Order: q.Order.replaceDB(db),
|
||||
PrepTask: q.PrepTask.replaceDB(db),
|
||||
ProductType: q.ProductType.replaceDB(db),
|
||||
Shift: q.Shift.replaceDB(db),
|
||||
Task: q.Task.replaceDB(db),
|
||||
TeamTask: q.TeamTask.replaceDB(db),
|
||||
TeamType: q.TeamType.replaceDB(db),
|
||||
WorkArea: q.WorkArea.replaceDB(db),
|
||||
Worker: q.Worker.replaceDB(db),
|
||||
Workshop: q.Workshop.replaceDB(db),
|
||||
db: db,
|
||||
Post: q.Post.replaceDB(db),
|
||||
}
|
||||
}
|
||||
|
||||
type queryCtx struct {
|
||||
Customer ICustomerDo
|
||||
Order IOrderDo
|
||||
PrepTask IPrepTaskDo
|
||||
ProductType IProductTypeDo
|
||||
Shift IShiftDo
|
||||
Task ITaskDo
|
||||
TeamTask ITeamTaskDo
|
||||
TeamType ITeamTypeDo
|
||||
WorkArea IWorkAreaDo
|
||||
Worker IWorkerDo
|
||||
Workshop IWorkshopDo
|
||||
Post IPostDo
|
||||
}
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
Customer: q.Customer.WithContext(ctx),
|
||||
Order: q.Order.WithContext(ctx),
|
||||
PrepTask: q.PrepTask.WithContext(ctx),
|
||||
ProductType: q.ProductType.WithContext(ctx),
|
||||
Shift: q.Shift.WithContext(ctx),
|
||||
Task: q.Task.WithContext(ctx),
|
||||
TeamTask: q.TeamTask.WithContext(ctx),
|
||||
TeamType: q.TeamType.WithContext(ctx),
|
||||
WorkArea: q.WorkArea.WithContext(ctx),
|
||||
Worker: q.Worker.WithContext(ctx),
|
||||
Workshop: q.Workshop.WithContext(ctx),
|
||||
Post: q.Post.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,17 +77,7 @@ func Test_WithContext(t *testing.T) {
|
||||
qCtx := query.WithContext(context.WithValue(context.Background(), key, value))
|
||||
|
||||
for _, ctx := range []context.Context{
|
||||
qCtx.Customer.UnderlyingDB().Statement.Context,
|
||||
qCtx.Order.UnderlyingDB().Statement.Context,
|
||||
qCtx.PrepTask.UnderlyingDB().Statement.Context,
|
||||
qCtx.ProductType.UnderlyingDB().Statement.Context,
|
||||
qCtx.Shift.UnderlyingDB().Statement.Context,
|
||||
qCtx.Task.UnderlyingDB().Statement.Context,
|
||||
qCtx.TeamTask.UnderlyingDB().Statement.Context,
|
||||
qCtx.TeamType.UnderlyingDB().Statement.Context,
|
||||
qCtx.WorkArea.UnderlyingDB().Statement.Context,
|
||||
qCtx.Worker.UnderlyingDB().Statement.Context,
|
||||
qCtx.Workshop.UnderlyingDB().Statement.Context,
|
||||
qCtx.Post.UnderlyingDB().Statement.Context,
|
||||
} {
|
||||
if v := ctx.Value(key); v != value {
|
||||
t.Errorf("get value from context fail, expect %q, got %q", value, v)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,145 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func init() {
|
||||
InitializeDB()
|
||||
err := _gen_test_db.AutoMigrate(&models.Order{})
|
||||
if err != nil {
|
||||
fmt.Printf("Error: AutoMigrate(&models.Order{}) fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_orderQuery(t *testing.T) {
|
||||
order := newOrder(_gen_test_db)
|
||||
order = *order.As(order.TableName())
|
||||
_do := order.WithContext(context.Background()).Debug()
|
||||
|
||||
primaryKey := field.NewString(order.TableName(), clause.PrimaryKey)
|
||||
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
|
||||
if err != nil {
|
||||
t.Error("clean table <orders> fail:", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, ok := order.GetFieldByName("")
|
||||
if ok {
|
||||
t.Error("GetFieldByName(\"\") from order success")
|
||||
}
|
||||
|
||||
err = _do.Create(&models.Order{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <orders> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Save(&models.Order{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <orders> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.CreateInBatches([]*models.Order{{}, {}}, 10)
|
||||
if err != nil {
|
||||
t.Error("create item in table <orders> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(order.ALL).Take()
|
||||
if err != nil {
|
||||
t.Error("Take() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.First()
|
||||
if err != nil {
|
||||
t.Error("First() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Last()
|
||||
if err != nil {
|
||||
t.Error("First() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatch() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*models.Order{}, 10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatches() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(order.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
|
||||
if err != nil {
|
||||
t.Error("Find() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Distinct(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("select Distinct() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(order.ALL).Omit(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("Omit() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Group(primaryKey).Find()
|
||||
if err != nil {
|
||||
t.Error("Group() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
|
||||
if err != nil {
|
||||
t.Error("Scopes() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
_, _, err = _do.FindByPage(0, 1)
|
||||
if err != nil {
|
||||
t.Error("FindByPage() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.ScanByPage(&models.Order{}, 0, 1)
|
||||
if err != nil {
|
||||
t.Error("ScanByPage() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
|
||||
if err != nil {
|
||||
t.Error("FirstOrInit() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
|
||||
if err != nil {
|
||||
t.Error("FirstOrCreate() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
var _a _another
|
||||
var _aPK = field.NewString(_a.TableName(), "id")
|
||||
|
||||
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("Join() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("LeftJoin() on table <orders> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Not().Or().Clauses().Take()
|
||||
if err != nil {
|
||||
t.Error("Not/Or/Clauses on table <orders> fail:", err)
|
||||
}
|
||||
}
|
||||
383
internal/dal/posts.gen.go
Normal file
383
internal/dal/posts.gen.go
Normal file
@@ -0,0 +1,383 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newPost(db *gorm.DB, opts ...gen.DOOption) post {
|
||||
_post := post{}
|
||||
|
||||
_post.postDo.UseDB(db, opts...)
|
||||
_post.postDo.UseModel(&models.Post{})
|
||||
|
||||
tableName := _post.postDo.TableName()
|
||||
_post.ALL = field.NewAsterisk(tableName)
|
||||
_post.Id = field.NewUint(tableName, "id")
|
||||
_post.Text = field.NewString(tableName, "text")
|
||||
|
||||
_post.fillFieldMap()
|
||||
|
||||
return _post
|
||||
}
|
||||
|
||||
type post struct {
|
||||
postDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
Text field.String
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p post) Table(newTableName string) *post {
|
||||
p.postDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p post) As(alias string) *post {
|
||||
p.postDo.DO = *(p.postDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *post) updateTableName(table string) *post {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.Id = field.NewUint(table, "id")
|
||||
p.Text = field.NewString(table, "text")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *post) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *post) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 2)
|
||||
p.fieldMap["id"] = p.Id
|
||||
p.fieldMap["text"] = p.Text
|
||||
}
|
||||
|
||||
func (p post) clone(db *gorm.DB) post {
|
||||
p.postDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p post) replaceDB(db *gorm.DB) post {
|
||||
p.postDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type postDo struct{ gen.DO }
|
||||
|
||||
type IPostDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IPostDo
|
||||
WithContext(ctx context.Context) IPostDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IPostDo
|
||||
WriteDB() IPostDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IPostDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IPostDo
|
||||
Not(conds ...gen.Condition) IPostDo
|
||||
Or(conds ...gen.Condition) IPostDo
|
||||
Select(conds ...field.Expr) IPostDo
|
||||
Where(conds ...gen.Condition) IPostDo
|
||||
Order(conds ...field.Expr) IPostDo
|
||||
Distinct(cols ...field.Expr) IPostDo
|
||||
Omit(cols ...field.Expr) IPostDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IPostDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IPostDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IPostDo
|
||||
Group(cols ...field.Expr) IPostDo
|
||||
Having(conds ...gen.Condition) IPostDo
|
||||
Limit(limit int) IPostDo
|
||||
Offset(offset int) IPostDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IPostDo
|
||||
Unscoped() IPostDo
|
||||
Create(values ...*models.Post) error
|
||||
CreateInBatches(values []*models.Post, batchSize int) error
|
||||
Save(values ...*models.Post) error
|
||||
First() (*models.Post, error)
|
||||
Take() (*models.Post, error)
|
||||
Last() (*models.Post, error)
|
||||
Find() ([]*models.Post, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Post, err error)
|
||||
FindInBatches(result *[]*models.Post, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*models.Post) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IPostDo
|
||||
Assign(attrs ...field.AssignExpr) IPostDo
|
||||
Joins(fields ...field.RelationField) IPostDo
|
||||
Preload(fields ...field.RelationField) IPostDo
|
||||
FirstOrInit() (*models.Post, error)
|
||||
FirstOrCreate() (*models.Post, error)
|
||||
FindByPage(offset int, limit int) (result []*models.Post, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IPostDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (p postDo) Debug() IPostDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p postDo) WithContext(ctx context.Context) IPostDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p postDo) ReadDB() IPostDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p postDo) WriteDB() IPostDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p postDo) Session(config *gorm.Session) IPostDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p postDo) Clauses(conds ...clause.Expression) IPostDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p postDo) Returning(value interface{}, columns ...string) IPostDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p postDo) Not(conds ...gen.Condition) IPostDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p postDo) Or(conds ...gen.Condition) IPostDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p postDo) Select(conds ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p postDo) Where(conds ...gen.Condition) IPostDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p postDo) Order(conds ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p postDo) Distinct(cols ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p postDo) Omit(cols ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p postDo) Join(table schema.Tabler, on ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p postDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p postDo) RightJoin(table schema.Tabler, on ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p postDo) Group(cols ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p postDo) Having(conds ...gen.Condition) IPostDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p postDo) Limit(limit int) IPostDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p postDo) Offset(offset int) IPostDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p postDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPostDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p postDo) Unscoped() IPostDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p postDo) Create(values ...*models.Post) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p postDo) CreateInBatches(values []*models.Post, batchSize int) error {
|
||||
return p.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (p postDo) Save(values ...*models.Post) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p postDo) First() (*models.Post, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Post), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postDo) Take() (*models.Post, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Post), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postDo) Last() (*models.Post, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Post), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postDo) Find() ([]*models.Post, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*models.Post), err
|
||||
}
|
||||
|
||||
func (p postDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Post, err error) {
|
||||
buf := make([]*models.Post, 0, batchSize)
|
||||
err = p.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (p postDo) FindInBatches(result *[]*models.Post, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p postDo) Attrs(attrs ...field.AssignExpr) IPostDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p postDo) Assign(attrs ...field.AssignExpr) IPostDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p postDo) Joins(fields ...field.RelationField) IPostDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p postDo) Preload(fields ...field.RelationField) IPostDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p postDo) FirstOrInit() (*models.Post, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Post), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postDo) FirstOrCreate() (*models.Post, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Post), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postDo) FindByPage(offset int, limit int) (result []*models.Post, count int64, err error) {
|
||||
result, err = p.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p postDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p postDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p postDo) Delete(models ...*models.Post) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *postDo) withDO(do gen.Dao) *postDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
||||
145
internal/dal/posts.gen_test.go
Normal file
145
internal/dal/posts.gen_test.go
Normal file
@@ -0,0 +1,145 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func init() {
|
||||
InitializeDB()
|
||||
err := _gen_test_db.AutoMigrate(&models.Post{})
|
||||
if err != nil {
|
||||
fmt.Printf("Error: AutoMigrate(&models.Post{}) fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_postQuery(t *testing.T) {
|
||||
post := newPost(_gen_test_db)
|
||||
post = *post.As(post.TableName())
|
||||
_do := post.WithContext(context.Background()).Debug()
|
||||
|
||||
primaryKey := field.NewString(post.TableName(), clause.PrimaryKey)
|
||||
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
|
||||
if err != nil {
|
||||
t.Error("clean table <posts> fail:", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, ok := post.GetFieldByName("")
|
||||
if ok {
|
||||
t.Error("GetFieldByName(\"\") from post success")
|
||||
}
|
||||
|
||||
err = _do.Create(&models.Post{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <posts> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Save(&models.Post{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <posts> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.CreateInBatches([]*models.Post{{}, {}}, 10)
|
||||
if err != nil {
|
||||
t.Error("create item in table <posts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(post.ALL).Take()
|
||||
if err != nil {
|
||||
t.Error("Take() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.First()
|
||||
if err != nil {
|
||||
t.Error("First() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Last()
|
||||
if err != nil {
|
||||
t.Error("First() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatch() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*models.Post{}, 10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatches() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(post.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
|
||||
if err != nil {
|
||||
t.Error("Find() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Distinct(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("select Distinct() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(post.ALL).Omit(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("Omit() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Group(primaryKey).Find()
|
||||
if err != nil {
|
||||
t.Error("Group() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
|
||||
if err != nil {
|
||||
t.Error("Scopes() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
_, _, err = _do.FindByPage(0, 1)
|
||||
if err != nil {
|
||||
t.Error("FindByPage() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.ScanByPage(&models.Post{}, 0, 1)
|
||||
if err != nil {
|
||||
t.Error("ScanByPage() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
|
||||
if err != nil {
|
||||
t.Error("FirstOrInit() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
|
||||
if err != nil {
|
||||
t.Error("FirstOrCreate() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
var _a _another
|
||||
var _aPK = field.NewString(_a.TableName(), "id")
|
||||
|
||||
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("Join() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("LeftJoin() on table <posts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Not().Or().Clauses().Take()
|
||||
if err != nil {
|
||||
t.Error("Not/Or/Clauses on table <posts> fail:", err)
|
||||
}
|
||||
}
|
||||
@@ -1,935 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newPrepTask(db *gorm.DB, opts ...gen.DOOption) prepTask {
|
||||
_prepTask := prepTask{}
|
||||
|
||||
_prepTask.prepTaskDo.UseDB(db, opts...)
|
||||
_prepTask.prepTaskDo.UseModel(&models.PrepTask{})
|
||||
|
||||
tableName := _prepTask.prepTaskDo.TableName()
|
||||
_prepTask.ALL = field.NewAsterisk(tableName)
|
||||
_prepTask.Id = field.NewUint(tableName, "id")
|
||||
_prepTask.Status = field.NewString(tableName, "status")
|
||||
_prepTask.Description = field.NewString(tableName, "description")
|
||||
_prepTask.TaskId = field.NewUint(tableName, "task_id")
|
||||
_prepTask.WorkAreaId = field.NewUint(tableName, "work_area_id")
|
||||
_prepTask.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_prepTask.Deadline = field.NewInt64(tableName, "deadline")
|
||||
_prepTask.Task = prepTaskBelongsToTask{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Task", "models.Task"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.ProductType", "models.ProductType"),
|
||||
},
|
||||
Order: struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.Order", "models.Order"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.Order.ProductType", "models.ProductType"),
|
||||
},
|
||||
Customer: struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.Order.Customer", "models.Customer"),
|
||||
Orders: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.Order.Customer.Orders", "models.Order"),
|
||||
},
|
||||
},
|
||||
Tasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.Order.Tasks", "models.Task"),
|
||||
},
|
||||
},
|
||||
PrepTasks: struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
WorkAreas struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workers struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
Shifts struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks", "models.PrepTask"),
|
||||
Task: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.Task", "models.Task"),
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
WorkAreas struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workers struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
Shifts struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea", "models.WorkArea"),
|
||||
Workshop: struct {
|
||||
field.RelationField
|
||||
WorkAreas struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workers struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop", "models.Workshop"),
|
||||
WorkAreas: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.WorkAreas", "models.WorkArea"),
|
||||
},
|
||||
Workers: struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Workers", "models.Worker"),
|
||||
Workshop: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Workers.Workshop", "models.Workshop"),
|
||||
},
|
||||
TeamTasks: struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Workers.TeamTasks", "models.TeamTask"),
|
||||
TeamType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Workers.TeamTasks.TeamType", "models.TeamType"),
|
||||
},
|
||||
TeamLeader: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Workers.TeamTasks.TeamLeader", "models.Worker"),
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Workers.TeamTasks.WorkArea", "models.WorkArea"),
|
||||
},
|
||||
TeamMembers: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Workers.TeamTasks.TeamMembers", "models.Worker"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Tasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Tasks", "models.Task"),
|
||||
},
|
||||
},
|
||||
PrepTasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.PrepTasks", "models.PrepTask"),
|
||||
},
|
||||
Shifts: struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Shifts", "models.Shift"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Shifts.ProductType", "models.ProductType"),
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Shifts.WorkArea", "models.WorkArea"),
|
||||
},
|
||||
},
|
||||
TeamTasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.PrepTasks.WorkArea.TeamTasks", "models.TeamTask"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Workshops: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Task.Workshops", "models.Workshop"),
|
||||
},
|
||||
}
|
||||
|
||||
_prepTask.WorkArea = prepTaskBelongsToWorkArea{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("WorkArea", "models.WorkArea"),
|
||||
}
|
||||
|
||||
_prepTask.fillFieldMap()
|
||||
|
||||
return _prepTask
|
||||
}
|
||||
|
||||
type prepTask struct {
|
||||
prepTaskDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
Status field.String
|
||||
Description field.String
|
||||
TaskId field.Uint
|
||||
WorkAreaId field.Uint
|
||||
CreatedAt field.Int64
|
||||
Deadline field.Int64
|
||||
Task prepTaskBelongsToTask
|
||||
|
||||
WorkArea prepTaskBelongsToWorkArea
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p prepTask) Table(newTableName string) *prepTask {
|
||||
p.prepTaskDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p prepTask) As(alias string) *prepTask {
|
||||
p.prepTaskDo.DO = *(p.prepTaskDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *prepTask) updateTableName(table string) *prepTask {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.Id = field.NewUint(table, "id")
|
||||
p.Status = field.NewString(table, "status")
|
||||
p.Description = field.NewString(table, "description")
|
||||
p.TaskId = field.NewUint(table, "task_id")
|
||||
p.WorkAreaId = field.NewUint(table, "work_area_id")
|
||||
p.CreatedAt = field.NewInt64(table, "created_at")
|
||||
p.Deadline = field.NewInt64(table, "deadline")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *prepTask) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *prepTask) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 9)
|
||||
p.fieldMap["id"] = p.Id
|
||||
p.fieldMap["status"] = p.Status
|
||||
p.fieldMap["description"] = p.Description
|
||||
p.fieldMap["task_id"] = p.TaskId
|
||||
p.fieldMap["work_area_id"] = p.WorkAreaId
|
||||
p.fieldMap["created_at"] = p.CreatedAt
|
||||
p.fieldMap["deadline"] = p.Deadline
|
||||
|
||||
}
|
||||
|
||||
func (p prepTask) clone(db *gorm.DB) prepTask {
|
||||
p.prepTaskDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p prepTask) replaceDB(db *gorm.DB) prepTask {
|
||||
p.prepTaskDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type prepTaskBelongsToTask struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Order struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
WorkAreas struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workers struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
Shifts struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Workshops struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToTask) Where(conds ...field.Expr) *prepTaskBelongsToTask {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToTask) WithContext(ctx context.Context) *prepTaskBelongsToTask {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToTask) Session(session *gorm.Session) *prepTaskBelongsToTask {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToTask) Model(m *models.PrepTask) *prepTaskBelongsToTaskTx {
|
||||
return &prepTaskBelongsToTaskTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type prepTaskBelongsToTaskTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a prepTaskBelongsToTaskTx) Find() (result *models.Task, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToTaskTx) Append(values ...*models.Task) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToTaskTx) Replace(values ...*models.Task) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToTaskTx) Delete(values ...*models.Task) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToTaskTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToTaskTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type prepTaskBelongsToWorkArea struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToWorkArea) Where(conds ...field.Expr) *prepTaskBelongsToWorkArea {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToWorkArea) WithContext(ctx context.Context) *prepTaskBelongsToWorkArea {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToWorkArea) Session(session *gorm.Session) *prepTaskBelongsToWorkArea {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToWorkArea) Model(m *models.PrepTask) *prepTaskBelongsToWorkAreaTx {
|
||||
return &prepTaskBelongsToWorkAreaTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type prepTaskBelongsToWorkAreaTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a prepTaskBelongsToWorkAreaTx) Find() (result *models.WorkArea, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToWorkAreaTx) Append(values ...*models.WorkArea) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToWorkAreaTx) Replace(values ...*models.WorkArea) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToWorkAreaTx) Delete(values ...*models.WorkArea) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToWorkAreaTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a prepTaskBelongsToWorkAreaTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type prepTaskDo struct{ gen.DO }
|
||||
|
||||
type IPrepTaskDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IPrepTaskDo
|
||||
WithContext(ctx context.Context) IPrepTaskDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IPrepTaskDo
|
||||
WriteDB() IPrepTaskDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IPrepTaskDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IPrepTaskDo
|
||||
Not(conds ...gen.Condition) IPrepTaskDo
|
||||
Or(conds ...gen.Condition) IPrepTaskDo
|
||||
Select(conds ...field.Expr) IPrepTaskDo
|
||||
Where(conds ...gen.Condition) IPrepTaskDo
|
||||
Order(conds ...field.Expr) IPrepTaskDo
|
||||
Distinct(cols ...field.Expr) IPrepTaskDo
|
||||
Omit(cols ...field.Expr) IPrepTaskDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IPrepTaskDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IPrepTaskDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IPrepTaskDo
|
||||
Group(cols ...field.Expr) IPrepTaskDo
|
||||
Having(conds ...gen.Condition) IPrepTaskDo
|
||||
Limit(limit int) IPrepTaskDo
|
||||
Offset(offset int) IPrepTaskDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IPrepTaskDo
|
||||
Unscoped() IPrepTaskDo
|
||||
Create(values ...*models.PrepTask) error
|
||||
CreateInBatches(values []*models.PrepTask, batchSize int) error
|
||||
Save(values ...*models.PrepTask) error
|
||||
First() (*models.PrepTask, error)
|
||||
Take() (*models.PrepTask, error)
|
||||
Last() (*models.PrepTask, error)
|
||||
Find() ([]*models.PrepTask, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.PrepTask, err error)
|
||||
FindInBatches(result *[]*models.PrepTask, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*models.PrepTask) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IPrepTaskDo
|
||||
Assign(attrs ...field.AssignExpr) IPrepTaskDo
|
||||
Joins(fields ...field.RelationField) IPrepTaskDo
|
||||
Preload(fields ...field.RelationField) IPrepTaskDo
|
||||
FirstOrInit() (*models.PrepTask, error)
|
||||
FirstOrCreate() (*models.PrepTask, error)
|
||||
FindByPage(offset int, limit int) (result []*models.PrepTask, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IPrepTaskDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Debug() IPrepTaskDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p prepTaskDo) WithContext(ctx context.Context) IPrepTaskDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) ReadDB() IPrepTaskDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p prepTaskDo) WriteDB() IPrepTaskDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Session(config *gorm.Session) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Clauses(conds ...clause.Expression) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Returning(value interface{}, columns ...string) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Not(conds ...gen.Condition) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Or(conds ...gen.Condition) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Select(conds ...field.Expr) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Where(conds ...gen.Condition) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Order(conds ...field.Expr) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Distinct(cols ...field.Expr) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Omit(cols ...field.Expr) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Join(table schema.Tabler, on ...field.Expr) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPrepTaskDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) RightJoin(table schema.Tabler, on ...field.Expr) IPrepTaskDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Group(cols ...field.Expr) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Having(conds ...gen.Condition) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Limit(limit int) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Offset(offset int) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Unscoped() IPrepTaskDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Create(values ...*models.PrepTask) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p prepTaskDo) CreateInBatches(values []*models.PrepTask, batchSize int) error {
|
||||
return p.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (p prepTaskDo) Save(values ...*models.PrepTask) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p prepTaskDo) First() (*models.PrepTask, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.PrepTask), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Take() (*models.PrepTask, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.PrepTask), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Last() (*models.PrepTask, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.PrepTask), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Find() ([]*models.PrepTask, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*models.PrepTask), err
|
||||
}
|
||||
|
||||
func (p prepTaskDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.PrepTask, err error) {
|
||||
buf := make([]*models.PrepTask, 0, batchSize)
|
||||
err = p.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (p prepTaskDo) FindInBatches(result *[]*models.PrepTask, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Attrs(attrs ...field.AssignExpr) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Assign(attrs ...field.AssignExpr) IPrepTaskDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Joins(fields ...field.RelationField) IPrepTaskDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Preload(fields ...field.RelationField) IPrepTaskDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p prepTaskDo) FirstOrInit() (*models.PrepTask, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.PrepTask), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p prepTaskDo) FirstOrCreate() (*models.PrepTask, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.PrepTask), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p prepTaskDo) FindByPage(offset int, limit int) (result []*models.PrepTask, count int64, err error) {
|
||||
result, err = p.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p prepTaskDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p prepTaskDo) Delete(models ...*models.PrepTask) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *prepTaskDo) withDO(do gen.Dao) *prepTaskDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func init() {
|
||||
InitializeDB()
|
||||
err := _gen_test_db.AutoMigrate(&models.PrepTask{})
|
||||
if err != nil {
|
||||
fmt.Printf("Error: AutoMigrate(&models.PrepTask{}) fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_prepTaskQuery(t *testing.T) {
|
||||
prepTask := newPrepTask(_gen_test_db)
|
||||
prepTask = *prepTask.As(prepTask.TableName())
|
||||
_do := prepTask.WithContext(context.Background()).Debug()
|
||||
|
||||
primaryKey := field.NewString(prepTask.TableName(), clause.PrimaryKey)
|
||||
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
|
||||
if err != nil {
|
||||
t.Error("clean table <prep_tasks> fail:", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, ok := prepTask.GetFieldByName("")
|
||||
if ok {
|
||||
t.Error("GetFieldByName(\"\") from prepTask success")
|
||||
}
|
||||
|
||||
err = _do.Create(&models.PrepTask{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Save(&models.PrepTask{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.CreateInBatches([]*models.PrepTask{{}, {}}, 10)
|
||||
if err != nil {
|
||||
t.Error("create item in table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(prepTask.ALL).Take()
|
||||
if err != nil {
|
||||
t.Error("Take() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.First()
|
||||
if err != nil {
|
||||
t.Error("First() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Last()
|
||||
if err != nil {
|
||||
t.Error("First() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatch() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*models.PrepTask{}, 10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatches() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(prepTask.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
|
||||
if err != nil {
|
||||
t.Error("Find() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Distinct(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("select Distinct() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(prepTask.ALL).Omit(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("Omit() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Group(primaryKey).Find()
|
||||
if err != nil {
|
||||
t.Error("Group() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
|
||||
if err != nil {
|
||||
t.Error("Scopes() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, _, err = _do.FindByPage(0, 1)
|
||||
if err != nil {
|
||||
t.Error("FindByPage() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.ScanByPage(&models.PrepTask{}, 0, 1)
|
||||
if err != nil {
|
||||
t.Error("ScanByPage() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
|
||||
if err != nil {
|
||||
t.Error("FirstOrInit() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
|
||||
if err != nil {
|
||||
t.Error("FirstOrCreate() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
var _a _another
|
||||
var _aPK = field.NewString(_a.TableName(), "id")
|
||||
|
||||
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("Join() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("LeftJoin() on table <prep_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Not().Or().Clauses().Take()
|
||||
if err != nil {
|
||||
t.Error("Not/Or/Clauses on table <prep_tasks> fail:", err)
|
||||
}
|
||||
}
|
||||
@@ -1,383 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newProductType(db *gorm.DB, opts ...gen.DOOption) productType {
|
||||
_productType := productType{}
|
||||
|
||||
_productType.productTypeDo.UseDB(db, opts...)
|
||||
_productType.productTypeDo.UseModel(&models.ProductType{})
|
||||
|
||||
tableName := _productType.productTypeDo.TableName()
|
||||
_productType.ALL = field.NewAsterisk(tableName)
|
||||
_productType.Id = field.NewUint(tableName, "id")
|
||||
_productType.Name = field.NewString(tableName, "name")
|
||||
|
||||
_productType.fillFieldMap()
|
||||
|
||||
return _productType
|
||||
}
|
||||
|
||||
type productType struct {
|
||||
productTypeDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
Name field.String
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p productType) Table(newTableName string) *productType {
|
||||
p.productTypeDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p productType) As(alias string) *productType {
|
||||
p.productTypeDo.DO = *(p.productTypeDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *productType) updateTableName(table string) *productType {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.Id = field.NewUint(table, "id")
|
||||
p.Name = field.NewString(table, "name")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *productType) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *productType) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 2)
|
||||
p.fieldMap["id"] = p.Id
|
||||
p.fieldMap["name"] = p.Name
|
||||
}
|
||||
|
||||
func (p productType) clone(db *gorm.DB) productType {
|
||||
p.productTypeDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p productType) replaceDB(db *gorm.DB) productType {
|
||||
p.productTypeDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type productTypeDo struct{ gen.DO }
|
||||
|
||||
type IProductTypeDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IProductTypeDo
|
||||
WithContext(ctx context.Context) IProductTypeDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IProductTypeDo
|
||||
WriteDB() IProductTypeDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IProductTypeDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IProductTypeDo
|
||||
Not(conds ...gen.Condition) IProductTypeDo
|
||||
Or(conds ...gen.Condition) IProductTypeDo
|
||||
Select(conds ...field.Expr) IProductTypeDo
|
||||
Where(conds ...gen.Condition) IProductTypeDo
|
||||
Order(conds ...field.Expr) IProductTypeDo
|
||||
Distinct(cols ...field.Expr) IProductTypeDo
|
||||
Omit(cols ...field.Expr) IProductTypeDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IProductTypeDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IProductTypeDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IProductTypeDo
|
||||
Group(cols ...field.Expr) IProductTypeDo
|
||||
Having(conds ...gen.Condition) IProductTypeDo
|
||||
Limit(limit int) IProductTypeDo
|
||||
Offset(offset int) IProductTypeDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IProductTypeDo
|
||||
Unscoped() IProductTypeDo
|
||||
Create(values ...*models.ProductType) error
|
||||
CreateInBatches(values []*models.ProductType, batchSize int) error
|
||||
Save(values ...*models.ProductType) error
|
||||
First() (*models.ProductType, error)
|
||||
Take() (*models.ProductType, error)
|
||||
Last() (*models.ProductType, error)
|
||||
Find() ([]*models.ProductType, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ProductType, err error)
|
||||
FindInBatches(result *[]*models.ProductType, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*models.ProductType) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IProductTypeDo
|
||||
Assign(attrs ...field.AssignExpr) IProductTypeDo
|
||||
Joins(fields ...field.RelationField) IProductTypeDo
|
||||
Preload(fields ...field.RelationField) IProductTypeDo
|
||||
FirstOrInit() (*models.ProductType, error)
|
||||
FirstOrCreate() (*models.ProductType, error)
|
||||
FindByPage(offset int, limit int) (result []*models.ProductType, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IProductTypeDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (p productTypeDo) Debug() IProductTypeDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p productTypeDo) WithContext(ctx context.Context) IProductTypeDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p productTypeDo) ReadDB() IProductTypeDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p productTypeDo) WriteDB() IProductTypeDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p productTypeDo) Session(config *gorm.Session) IProductTypeDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Clauses(conds ...clause.Expression) IProductTypeDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Returning(value interface{}, columns ...string) IProductTypeDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Not(conds ...gen.Condition) IProductTypeDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Or(conds ...gen.Condition) IProductTypeDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Select(conds ...field.Expr) IProductTypeDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Where(conds ...gen.Condition) IProductTypeDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Order(conds ...field.Expr) IProductTypeDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Distinct(cols ...field.Expr) IProductTypeDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Omit(cols ...field.Expr) IProductTypeDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Join(table schema.Tabler, on ...field.Expr) IProductTypeDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) LeftJoin(table schema.Tabler, on ...field.Expr) IProductTypeDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) RightJoin(table schema.Tabler, on ...field.Expr) IProductTypeDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Group(cols ...field.Expr) IProductTypeDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Having(conds ...gen.Condition) IProductTypeDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Limit(limit int) IProductTypeDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Offset(offset int) IProductTypeDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IProductTypeDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Unscoped() IProductTypeDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p productTypeDo) Create(values ...*models.ProductType) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p productTypeDo) CreateInBatches(values []*models.ProductType, batchSize int) error {
|
||||
return p.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (p productTypeDo) Save(values ...*models.ProductType) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p productTypeDo) First() (*models.ProductType, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ProductType), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p productTypeDo) Take() (*models.ProductType, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ProductType), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p productTypeDo) Last() (*models.ProductType, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ProductType), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p productTypeDo) Find() ([]*models.ProductType, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*models.ProductType), err
|
||||
}
|
||||
|
||||
func (p productTypeDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ProductType, err error) {
|
||||
buf := make([]*models.ProductType, 0, batchSize)
|
||||
err = p.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (p productTypeDo) FindInBatches(result *[]*models.ProductType, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p productTypeDo) Attrs(attrs ...field.AssignExpr) IProductTypeDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Assign(attrs ...field.AssignExpr) IProductTypeDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p productTypeDo) Joins(fields ...field.RelationField) IProductTypeDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p productTypeDo) Preload(fields ...field.RelationField) IProductTypeDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p productTypeDo) FirstOrInit() (*models.ProductType, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ProductType), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p productTypeDo) FirstOrCreate() (*models.ProductType, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ProductType), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p productTypeDo) FindByPage(offset int, limit int) (result []*models.ProductType, count int64, err error) {
|
||||
result, err = p.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p productTypeDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p productTypeDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p productTypeDo) Delete(models ...*models.ProductType) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *productTypeDo) withDO(do gen.Dao) *productTypeDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func init() {
|
||||
InitializeDB()
|
||||
err := _gen_test_db.AutoMigrate(&models.ProductType{})
|
||||
if err != nil {
|
||||
fmt.Printf("Error: AutoMigrate(&models.ProductType{}) fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_productTypeQuery(t *testing.T) {
|
||||
productType := newProductType(_gen_test_db)
|
||||
productType = *productType.As(productType.TableName())
|
||||
_do := productType.WithContext(context.Background()).Debug()
|
||||
|
||||
primaryKey := field.NewString(productType.TableName(), clause.PrimaryKey)
|
||||
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
|
||||
if err != nil {
|
||||
t.Error("clean table <product_types> fail:", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, ok := productType.GetFieldByName("")
|
||||
if ok {
|
||||
t.Error("GetFieldByName(\"\") from productType success")
|
||||
}
|
||||
|
||||
err = _do.Create(&models.ProductType{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Save(&models.ProductType{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.CreateInBatches([]*models.ProductType{{}, {}}, 10)
|
||||
if err != nil {
|
||||
t.Error("create item in table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(productType.ALL).Take()
|
||||
if err != nil {
|
||||
t.Error("Take() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.First()
|
||||
if err != nil {
|
||||
t.Error("First() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Last()
|
||||
if err != nil {
|
||||
t.Error("First() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatch() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*models.ProductType{}, 10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatches() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(productType.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
|
||||
if err != nil {
|
||||
t.Error("Find() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Distinct(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("select Distinct() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(productType.ALL).Omit(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("Omit() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Group(primaryKey).Find()
|
||||
if err != nil {
|
||||
t.Error("Group() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
|
||||
if err != nil {
|
||||
t.Error("Scopes() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
_, _, err = _do.FindByPage(0, 1)
|
||||
if err != nil {
|
||||
t.Error("FindByPage() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.ScanByPage(&models.ProductType{}, 0, 1)
|
||||
if err != nil {
|
||||
t.Error("ScanByPage() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
|
||||
if err != nil {
|
||||
t.Error("FirstOrInit() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
|
||||
if err != nil {
|
||||
t.Error("FirstOrCreate() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
var _a _another
|
||||
var _aPK = field.NewString(_a.TableName(), "id")
|
||||
|
||||
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("Join() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("LeftJoin() on table <product_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Not().Or().Clauses().Take()
|
||||
if err != nil {
|
||||
t.Error("Not/Or/Clauses on table <product_types> fail:", err)
|
||||
}
|
||||
}
|
||||
@@ -1,905 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newShift(db *gorm.DB, opts ...gen.DOOption) shift {
|
||||
_shift := shift{}
|
||||
|
||||
_shift.shiftDo.UseDB(db, opts...)
|
||||
_shift.shiftDo.UseModel(&models.Shift{})
|
||||
|
||||
tableName := _shift.shiftDo.TableName()
|
||||
_shift.ALL = field.NewAsterisk(tableName)
|
||||
_shift.Id = field.NewUint(tableName, "id")
|
||||
_shift.Description = field.NewString(tableName, "description")
|
||||
_shift.ProductTypeId = field.NewUint(tableName, "product_type_id")
|
||||
_shift.ProductAmount = field.NewUint(tableName, "product_amount")
|
||||
_shift.ShiftDate = field.NewInt64(tableName, "shift_date")
|
||||
_shift.WorkAreaId = field.NewUint(tableName, "work_area_id")
|
||||
_shift.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_shift.ProductType = shiftBelongsToProductType{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("ProductType", "models.ProductType"),
|
||||
}
|
||||
|
||||
_shift.WorkArea = shiftBelongsToWorkArea{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("WorkArea", "models.WorkArea"),
|
||||
Workshop: struct {
|
||||
field.RelationField
|
||||
WorkAreas struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workers struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Order struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Workshops struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop", "models.Workshop"),
|
||||
WorkAreas: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.WorkAreas", "models.WorkArea"),
|
||||
},
|
||||
Workers: struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Workers", "models.Worker"),
|
||||
Workshop: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Workers.Workshop", "models.Workshop"),
|
||||
},
|
||||
TeamTasks: struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Workers.TeamTasks", "models.TeamTask"),
|
||||
TeamType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Workers.TeamTasks.TeamType", "models.TeamType"),
|
||||
},
|
||||
TeamLeader: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Workers.TeamTasks.TeamLeader", "models.Worker"),
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Workers.TeamTasks.WorkArea", "models.WorkArea"),
|
||||
},
|
||||
TeamMembers: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Workers.TeamTasks.TeamMembers", "models.Worker"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Tasks: struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Order struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Workshops struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Tasks", "models.Task"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Tasks.ProductType", "models.ProductType"),
|
||||
},
|
||||
Order: struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Tasks.Order", "models.Order"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Tasks.Order.ProductType", "models.ProductType"),
|
||||
},
|
||||
Customer: struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Tasks.Order.Customer", "models.Customer"),
|
||||
Orders: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Tasks.Order.Customer.Orders", "models.Order"),
|
||||
},
|
||||
},
|
||||
Tasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Tasks.Order.Tasks", "models.Task"),
|
||||
},
|
||||
},
|
||||
PrepTasks: struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Tasks.PrepTasks", "models.PrepTask"),
|
||||
Task: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Tasks.PrepTasks.Task", "models.Task"),
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Tasks.PrepTasks.WorkArea", "models.WorkArea"),
|
||||
},
|
||||
},
|
||||
Workshops: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Workshop.Tasks.Workshops", "models.Workshop"),
|
||||
},
|
||||
},
|
||||
},
|
||||
PrepTasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.PrepTasks", "models.PrepTask"),
|
||||
},
|
||||
Shifts: struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Shifts", "models.Shift"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Shifts.ProductType", "models.ProductType"),
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.Shifts.WorkArea", "models.WorkArea"),
|
||||
},
|
||||
},
|
||||
TeamTasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkArea.TeamTasks", "models.TeamTask"),
|
||||
},
|
||||
}
|
||||
|
||||
_shift.fillFieldMap()
|
||||
|
||||
return _shift
|
||||
}
|
||||
|
||||
type shift struct {
|
||||
shiftDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
Description field.String
|
||||
ProductTypeId field.Uint
|
||||
ProductAmount field.Uint
|
||||
ShiftDate field.Int64
|
||||
WorkAreaId field.Uint
|
||||
CreatedAt field.Int64
|
||||
ProductType shiftBelongsToProductType
|
||||
|
||||
WorkArea shiftBelongsToWorkArea
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (s shift) Table(newTableName string) *shift {
|
||||
s.shiftDo.UseTable(newTableName)
|
||||
return s.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (s shift) As(alias string) *shift {
|
||||
s.shiftDo.DO = *(s.shiftDo.As(alias).(*gen.DO))
|
||||
return s.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (s *shift) updateTableName(table string) *shift {
|
||||
s.ALL = field.NewAsterisk(table)
|
||||
s.Id = field.NewUint(table, "id")
|
||||
s.Description = field.NewString(table, "description")
|
||||
s.ProductTypeId = field.NewUint(table, "product_type_id")
|
||||
s.ProductAmount = field.NewUint(table, "product_amount")
|
||||
s.ShiftDate = field.NewInt64(table, "shift_date")
|
||||
s.WorkAreaId = field.NewUint(table, "work_area_id")
|
||||
s.CreatedAt = field.NewInt64(table, "created_at")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *shift) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := s.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (s *shift) fillFieldMap() {
|
||||
s.fieldMap = make(map[string]field.Expr, 9)
|
||||
s.fieldMap["id"] = s.Id
|
||||
s.fieldMap["description"] = s.Description
|
||||
s.fieldMap["product_type_id"] = s.ProductTypeId
|
||||
s.fieldMap["product_amount"] = s.ProductAmount
|
||||
s.fieldMap["shift_date"] = s.ShiftDate
|
||||
s.fieldMap["work_area_id"] = s.WorkAreaId
|
||||
s.fieldMap["created_at"] = s.CreatedAt
|
||||
|
||||
}
|
||||
|
||||
func (s shift) clone(db *gorm.DB) shift {
|
||||
s.shiftDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s shift) replaceDB(db *gorm.DB) shift {
|
||||
s.shiftDo.ReplaceDB(db)
|
||||
return s
|
||||
}
|
||||
|
||||
type shiftBelongsToProductType struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a shiftBelongsToProductType) Where(conds ...field.Expr) *shiftBelongsToProductType {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a shiftBelongsToProductType) WithContext(ctx context.Context) *shiftBelongsToProductType {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a shiftBelongsToProductType) Session(session *gorm.Session) *shiftBelongsToProductType {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a shiftBelongsToProductType) Model(m *models.Shift) *shiftBelongsToProductTypeTx {
|
||||
return &shiftBelongsToProductTypeTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type shiftBelongsToProductTypeTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a shiftBelongsToProductTypeTx) Find() (result *models.ProductType, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a shiftBelongsToProductTypeTx) Append(values ...*models.ProductType) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a shiftBelongsToProductTypeTx) Replace(values ...*models.ProductType) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a shiftBelongsToProductTypeTx) Delete(values ...*models.ProductType) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a shiftBelongsToProductTypeTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a shiftBelongsToProductTypeTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type shiftBelongsToWorkArea struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
WorkAreas struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workers struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Order struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Workshops struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
Shifts struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
func (a shiftBelongsToWorkArea) Where(conds ...field.Expr) *shiftBelongsToWorkArea {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a shiftBelongsToWorkArea) WithContext(ctx context.Context) *shiftBelongsToWorkArea {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a shiftBelongsToWorkArea) Session(session *gorm.Session) *shiftBelongsToWorkArea {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a shiftBelongsToWorkArea) Model(m *models.Shift) *shiftBelongsToWorkAreaTx {
|
||||
return &shiftBelongsToWorkAreaTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type shiftBelongsToWorkAreaTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a shiftBelongsToWorkAreaTx) Find() (result *models.WorkArea, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a shiftBelongsToWorkAreaTx) Append(values ...*models.WorkArea) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a shiftBelongsToWorkAreaTx) Replace(values ...*models.WorkArea) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a shiftBelongsToWorkAreaTx) Delete(values ...*models.WorkArea) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a shiftBelongsToWorkAreaTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a shiftBelongsToWorkAreaTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type shiftDo struct{ gen.DO }
|
||||
|
||||
type IShiftDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IShiftDo
|
||||
WithContext(ctx context.Context) IShiftDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IShiftDo
|
||||
WriteDB() IShiftDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IShiftDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IShiftDo
|
||||
Not(conds ...gen.Condition) IShiftDo
|
||||
Or(conds ...gen.Condition) IShiftDo
|
||||
Select(conds ...field.Expr) IShiftDo
|
||||
Where(conds ...gen.Condition) IShiftDo
|
||||
Order(conds ...field.Expr) IShiftDo
|
||||
Distinct(cols ...field.Expr) IShiftDo
|
||||
Omit(cols ...field.Expr) IShiftDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IShiftDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IShiftDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IShiftDo
|
||||
Group(cols ...field.Expr) IShiftDo
|
||||
Having(conds ...gen.Condition) IShiftDo
|
||||
Limit(limit int) IShiftDo
|
||||
Offset(offset int) IShiftDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IShiftDo
|
||||
Unscoped() IShiftDo
|
||||
Create(values ...*models.Shift) error
|
||||
CreateInBatches(values []*models.Shift, batchSize int) error
|
||||
Save(values ...*models.Shift) error
|
||||
First() (*models.Shift, error)
|
||||
Take() (*models.Shift, error)
|
||||
Last() (*models.Shift, error)
|
||||
Find() ([]*models.Shift, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Shift, err error)
|
||||
FindInBatches(result *[]*models.Shift, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*models.Shift) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IShiftDo
|
||||
Assign(attrs ...field.AssignExpr) IShiftDo
|
||||
Joins(fields ...field.RelationField) IShiftDo
|
||||
Preload(fields ...field.RelationField) IShiftDo
|
||||
FirstOrInit() (*models.Shift, error)
|
||||
FirstOrCreate() (*models.Shift, error)
|
||||
FindByPage(offset int, limit int) (result []*models.Shift, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IShiftDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (s shiftDo) Debug() IShiftDo {
|
||||
return s.withDO(s.DO.Debug())
|
||||
}
|
||||
|
||||
func (s shiftDo) WithContext(ctx context.Context) IShiftDo {
|
||||
return s.withDO(s.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (s shiftDo) ReadDB() IShiftDo {
|
||||
return s.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (s shiftDo) WriteDB() IShiftDo {
|
||||
return s.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (s shiftDo) Session(config *gorm.Session) IShiftDo {
|
||||
return s.withDO(s.DO.Session(config))
|
||||
}
|
||||
|
||||
func (s shiftDo) Clauses(conds ...clause.Expression) IShiftDo {
|
||||
return s.withDO(s.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Returning(value interface{}, columns ...string) IShiftDo {
|
||||
return s.withDO(s.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Not(conds ...gen.Condition) IShiftDo {
|
||||
return s.withDO(s.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Or(conds ...gen.Condition) IShiftDo {
|
||||
return s.withDO(s.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Select(conds ...field.Expr) IShiftDo {
|
||||
return s.withDO(s.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Where(conds ...gen.Condition) IShiftDo {
|
||||
return s.withDO(s.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Order(conds ...field.Expr) IShiftDo {
|
||||
return s.withDO(s.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Distinct(cols ...field.Expr) IShiftDo {
|
||||
return s.withDO(s.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Omit(cols ...field.Expr) IShiftDo {
|
||||
return s.withDO(s.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Join(table schema.Tabler, on ...field.Expr) IShiftDo {
|
||||
return s.withDO(s.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (s shiftDo) LeftJoin(table schema.Tabler, on ...field.Expr) IShiftDo {
|
||||
return s.withDO(s.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s shiftDo) RightJoin(table schema.Tabler, on ...field.Expr) IShiftDo {
|
||||
return s.withDO(s.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Group(cols ...field.Expr) IShiftDo {
|
||||
return s.withDO(s.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Having(conds ...gen.Condition) IShiftDo {
|
||||
return s.withDO(s.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Limit(limit int) IShiftDo {
|
||||
return s.withDO(s.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (s shiftDo) Offset(offset int) IShiftDo {
|
||||
return s.withDO(s.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (s shiftDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IShiftDo {
|
||||
return s.withDO(s.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Unscoped() IShiftDo {
|
||||
return s.withDO(s.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (s shiftDo) Create(values ...*models.Shift) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Create(values)
|
||||
}
|
||||
|
||||
func (s shiftDo) CreateInBatches(values []*models.Shift, batchSize int) error {
|
||||
return s.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (s shiftDo) Save(values ...*models.Shift) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Save(values)
|
||||
}
|
||||
|
||||
func (s shiftDo) First() (*models.Shift, error) {
|
||||
if result, err := s.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Shift), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s shiftDo) Take() (*models.Shift, error) {
|
||||
if result, err := s.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Shift), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s shiftDo) Last() (*models.Shift, error) {
|
||||
if result, err := s.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Shift), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s shiftDo) Find() ([]*models.Shift, error) {
|
||||
result, err := s.DO.Find()
|
||||
return result.([]*models.Shift), err
|
||||
}
|
||||
|
||||
func (s shiftDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Shift, err error) {
|
||||
buf := make([]*models.Shift, 0, batchSize)
|
||||
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (s shiftDo) FindInBatches(result *[]*models.Shift, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return s.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (s shiftDo) Attrs(attrs ...field.AssignExpr) IShiftDo {
|
||||
return s.withDO(s.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Assign(attrs ...field.AssignExpr) IShiftDo {
|
||||
return s.withDO(s.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (s shiftDo) Joins(fields ...field.RelationField) IShiftDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Joins(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s shiftDo) Preload(fields ...field.RelationField) IShiftDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Preload(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s shiftDo) FirstOrInit() (*models.Shift, error) {
|
||||
if result, err := s.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Shift), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s shiftDo) FirstOrCreate() (*models.Shift, error) {
|
||||
if result, err := s.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Shift), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s shiftDo) FindByPage(offset int, limit int) (result []*models.Shift, count int64, err error) {
|
||||
result, err = s.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = s.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (s shiftDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = s.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (s shiftDo) Scan(result interface{}) (err error) {
|
||||
return s.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (s shiftDo) Delete(models ...*models.Shift) (result gen.ResultInfo, err error) {
|
||||
return s.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (s *shiftDo) withDO(do gen.Dao) *shiftDo {
|
||||
s.DO = *do.(*gen.DO)
|
||||
return s
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func init() {
|
||||
InitializeDB()
|
||||
err := _gen_test_db.AutoMigrate(&models.Shift{})
|
||||
if err != nil {
|
||||
fmt.Printf("Error: AutoMigrate(&models.Shift{}) fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_shiftQuery(t *testing.T) {
|
||||
shift := newShift(_gen_test_db)
|
||||
shift = *shift.As(shift.TableName())
|
||||
_do := shift.WithContext(context.Background()).Debug()
|
||||
|
||||
primaryKey := field.NewString(shift.TableName(), clause.PrimaryKey)
|
||||
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
|
||||
if err != nil {
|
||||
t.Error("clean table <shifts> fail:", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, ok := shift.GetFieldByName("")
|
||||
if ok {
|
||||
t.Error("GetFieldByName(\"\") from shift success")
|
||||
}
|
||||
|
||||
err = _do.Create(&models.Shift{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Save(&models.Shift{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.CreateInBatches([]*models.Shift{{}, {}}, 10)
|
||||
if err != nil {
|
||||
t.Error("create item in table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(shift.ALL).Take()
|
||||
if err != nil {
|
||||
t.Error("Take() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.First()
|
||||
if err != nil {
|
||||
t.Error("First() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Last()
|
||||
if err != nil {
|
||||
t.Error("First() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatch() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*models.Shift{}, 10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatches() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(shift.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
|
||||
if err != nil {
|
||||
t.Error("Find() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Distinct(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("select Distinct() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(shift.ALL).Omit(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("Omit() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Group(primaryKey).Find()
|
||||
if err != nil {
|
||||
t.Error("Group() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
|
||||
if err != nil {
|
||||
t.Error("Scopes() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
_, _, err = _do.FindByPage(0, 1)
|
||||
if err != nil {
|
||||
t.Error("FindByPage() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.ScanByPage(&models.Shift{}, 0, 1)
|
||||
if err != nil {
|
||||
t.Error("ScanByPage() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
|
||||
if err != nil {
|
||||
t.Error("FirstOrInit() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
|
||||
if err != nil {
|
||||
t.Error("FirstOrCreate() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
var _a _another
|
||||
var _aPK = field.NewString(_a.TableName(), "id")
|
||||
|
||||
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("Join() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("LeftJoin() on table <shifts> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Not().Or().Clauses().Take()
|
||||
if err != nil {
|
||||
t.Error("Not/Or/Clauses on table <shifts> fail:", err)
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,145 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func init() {
|
||||
InitializeDB()
|
||||
err := _gen_test_db.AutoMigrate(&models.Task{})
|
||||
if err != nil {
|
||||
fmt.Printf("Error: AutoMigrate(&models.Task{}) fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_taskQuery(t *testing.T) {
|
||||
task := newTask(_gen_test_db)
|
||||
task = *task.As(task.TableName())
|
||||
_do := task.WithContext(context.Background()).Debug()
|
||||
|
||||
primaryKey := field.NewString(task.TableName(), clause.PrimaryKey)
|
||||
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
|
||||
if err != nil {
|
||||
t.Error("clean table <tasks> fail:", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, ok := task.GetFieldByName("")
|
||||
if ok {
|
||||
t.Error("GetFieldByName(\"\") from task success")
|
||||
}
|
||||
|
||||
err = _do.Create(&models.Task{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Save(&models.Task{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.CreateInBatches([]*models.Task{{}, {}}, 10)
|
||||
if err != nil {
|
||||
t.Error("create item in table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(task.ALL).Take()
|
||||
if err != nil {
|
||||
t.Error("Take() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.First()
|
||||
if err != nil {
|
||||
t.Error("First() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Last()
|
||||
if err != nil {
|
||||
t.Error("First() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatch() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*models.Task{}, 10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatches() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(task.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
|
||||
if err != nil {
|
||||
t.Error("Find() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Distinct(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("select Distinct() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(task.ALL).Omit(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("Omit() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Group(primaryKey).Find()
|
||||
if err != nil {
|
||||
t.Error("Group() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
|
||||
if err != nil {
|
||||
t.Error("Scopes() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, _, err = _do.FindByPage(0, 1)
|
||||
if err != nil {
|
||||
t.Error("FindByPage() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.ScanByPage(&models.Task{}, 0, 1)
|
||||
if err != nil {
|
||||
t.Error("ScanByPage() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
|
||||
if err != nil {
|
||||
t.Error("FirstOrInit() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
|
||||
if err != nil {
|
||||
t.Error("FirstOrCreate() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
var _a _another
|
||||
var _aPK = field.NewString(_a.TableName(), "id")
|
||||
|
||||
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("Join() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("LeftJoin() on table <tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Not().Or().Clauses().Take()
|
||||
if err != nil {
|
||||
t.Error("Not/Or/Clauses on table <tasks> fail:", err)
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,145 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func init() {
|
||||
InitializeDB()
|
||||
err := _gen_test_db.AutoMigrate(&models.TeamTask{})
|
||||
if err != nil {
|
||||
fmt.Printf("Error: AutoMigrate(&models.TeamTask{}) fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_teamTaskQuery(t *testing.T) {
|
||||
teamTask := newTeamTask(_gen_test_db)
|
||||
teamTask = *teamTask.As(teamTask.TableName())
|
||||
_do := teamTask.WithContext(context.Background()).Debug()
|
||||
|
||||
primaryKey := field.NewString(teamTask.TableName(), clause.PrimaryKey)
|
||||
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
|
||||
if err != nil {
|
||||
t.Error("clean table <team_tasks> fail:", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, ok := teamTask.GetFieldByName("")
|
||||
if ok {
|
||||
t.Error("GetFieldByName(\"\") from teamTask success")
|
||||
}
|
||||
|
||||
err = _do.Create(&models.TeamTask{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Save(&models.TeamTask{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.CreateInBatches([]*models.TeamTask{{}, {}}, 10)
|
||||
if err != nil {
|
||||
t.Error("create item in table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(teamTask.ALL).Take()
|
||||
if err != nil {
|
||||
t.Error("Take() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.First()
|
||||
if err != nil {
|
||||
t.Error("First() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Last()
|
||||
if err != nil {
|
||||
t.Error("First() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatch() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*models.TeamTask{}, 10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatches() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(teamTask.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
|
||||
if err != nil {
|
||||
t.Error("Find() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Distinct(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("select Distinct() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(teamTask.ALL).Omit(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("Omit() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Group(primaryKey).Find()
|
||||
if err != nil {
|
||||
t.Error("Group() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
|
||||
if err != nil {
|
||||
t.Error("Scopes() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, _, err = _do.FindByPage(0, 1)
|
||||
if err != nil {
|
||||
t.Error("FindByPage() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.ScanByPage(&models.TeamTask{}, 0, 1)
|
||||
if err != nil {
|
||||
t.Error("ScanByPage() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
|
||||
if err != nil {
|
||||
t.Error("FirstOrInit() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
|
||||
if err != nil {
|
||||
t.Error("FirstOrCreate() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
var _a _another
|
||||
var _aPK = field.NewString(_a.TableName(), "id")
|
||||
|
||||
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("Join() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("LeftJoin() on table <team_tasks> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Not().Or().Clauses().Take()
|
||||
if err != nil {
|
||||
t.Error("Not/Or/Clauses on table <team_tasks> fail:", err)
|
||||
}
|
||||
}
|
||||
@@ -1,383 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newTeamType(db *gorm.DB, opts ...gen.DOOption) teamType {
|
||||
_teamType := teamType{}
|
||||
|
||||
_teamType.teamTypeDo.UseDB(db, opts...)
|
||||
_teamType.teamTypeDo.UseModel(&models.TeamType{})
|
||||
|
||||
tableName := _teamType.teamTypeDo.TableName()
|
||||
_teamType.ALL = field.NewAsterisk(tableName)
|
||||
_teamType.Id = field.NewUint(tableName, "id")
|
||||
_teamType.Name = field.NewString(tableName, "name")
|
||||
|
||||
_teamType.fillFieldMap()
|
||||
|
||||
return _teamType
|
||||
}
|
||||
|
||||
type teamType struct {
|
||||
teamTypeDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
Name field.String
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (t teamType) Table(newTableName string) *teamType {
|
||||
t.teamTypeDo.UseTable(newTableName)
|
||||
return t.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (t teamType) As(alias string) *teamType {
|
||||
t.teamTypeDo.DO = *(t.teamTypeDo.As(alias).(*gen.DO))
|
||||
return t.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (t *teamType) updateTableName(table string) *teamType {
|
||||
t.ALL = field.NewAsterisk(table)
|
||||
t.Id = field.NewUint(table, "id")
|
||||
t.Name = field.NewString(table, "name")
|
||||
|
||||
t.fillFieldMap()
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *teamType) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := t.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (t *teamType) fillFieldMap() {
|
||||
t.fieldMap = make(map[string]field.Expr, 2)
|
||||
t.fieldMap["id"] = t.Id
|
||||
t.fieldMap["name"] = t.Name
|
||||
}
|
||||
|
||||
func (t teamType) clone(db *gorm.DB) teamType {
|
||||
t.teamTypeDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return t
|
||||
}
|
||||
|
||||
func (t teamType) replaceDB(db *gorm.DB) teamType {
|
||||
t.teamTypeDo.ReplaceDB(db)
|
||||
return t
|
||||
}
|
||||
|
||||
type teamTypeDo struct{ gen.DO }
|
||||
|
||||
type ITeamTypeDo interface {
|
||||
gen.SubQuery
|
||||
Debug() ITeamTypeDo
|
||||
WithContext(ctx context.Context) ITeamTypeDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() ITeamTypeDo
|
||||
WriteDB() ITeamTypeDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) ITeamTypeDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) ITeamTypeDo
|
||||
Not(conds ...gen.Condition) ITeamTypeDo
|
||||
Or(conds ...gen.Condition) ITeamTypeDo
|
||||
Select(conds ...field.Expr) ITeamTypeDo
|
||||
Where(conds ...gen.Condition) ITeamTypeDo
|
||||
Order(conds ...field.Expr) ITeamTypeDo
|
||||
Distinct(cols ...field.Expr) ITeamTypeDo
|
||||
Omit(cols ...field.Expr) ITeamTypeDo
|
||||
Join(table schema.Tabler, on ...field.Expr) ITeamTypeDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) ITeamTypeDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) ITeamTypeDo
|
||||
Group(cols ...field.Expr) ITeamTypeDo
|
||||
Having(conds ...gen.Condition) ITeamTypeDo
|
||||
Limit(limit int) ITeamTypeDo
|
||||
Offset(offset int) ITeamTypeDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) ITeamTypeDo
|
||||
Unscoped() ITeamTypeDo
|
||||
Create(values ...*models.TeamType) error
|
||||
CreateInBatches(values []*models.TeamType, batchSize int) error
|
||||
Save(values ...*models.TeamType) error
|
||||
First() (*models.TeamType, error)
|
||||
Take() (*models.TeamType, error)
|
||||
Last() (*models.TeamType, error)
|
||||
Find() ([]*models.TeamType, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.TeamType, err error)
|
||||
FindInBatches(result *[]*models.TeamType, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*models.TeamType) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) ITeamTypeDo
|
||||
Assign(attrs ...field.AssignExpr) ITeamTypeDo
|
||||
Joins(fields ...field.RelationField) ITeamTypeDo
|
||||
Preload(fields ...field.RelationField) ITeamTypeDo
|
||||
FirstOrInit() (*models.TeamType, error)
|
||||
FirstOrCreate() (*models.TeamType, error)
|
||||
FindByPage(offset int, limit int) (result []*models.TeamType, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) ITeamTypeDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Debug() ITeamTypeDo {
|
||||
return t.withDO(t.DO.Debug())
|
||||
}
|
||||
|
||||
func (t teamTypeDo) WithContext(ctx context.Context) ITeamTypeDo {
|
||||
return t.withDO(t.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) ReadDB() ITeamTypeDo {
|
||||
return t.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (t teamTypeDo) WriteDB() ITeamTypeDo {
|
||||
return t.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Session(config *gorm.Session) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Session(config))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Clauses(conds ...clause.Expression) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Returning(value interface{}, columns ...string) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Not(conds ...gen.Condition) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Or(conds ...gen.Condition) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Select(conds ...field.Expr) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Where(conds ...gen.Condition) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Order(conds ...field.Expr) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Distinct(cols ...field.Expr) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Omit(cols ...field.Expr) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Join(table schema.Tabler, on ...field.Expr) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) LeftJoin(table schema.Tabler, on ...field.Expr) ITeamTypeDo {
|
||||
return t.withDO(t.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) RightJoin(table schema.Tabler, on ...field.Expr) ITeamTypeDo {
|
||||
return t.withDO(t.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Group(cols ...field.Expr) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Having(conds ...gen.Condition) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Limit(limit int) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Offset(offset int) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Unscoped() ITeamTypeDo {
|
||||
return t.withDO(t.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Create(values ...*models.TeamType) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Create(values)
|
||||
}
|
||||
|
||||
func (t teamTypeDo) CreateInBatches(values []*models.TeamType, batchSize int) error {
|
||||
return t.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (t teamTypeDo) Save(values ...*models.TeamType) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Save(values)
|
||||
}
|
||||
|
||||
func (t teamTypeDo) First() (*models.TeamType, error) {
|
||||
if result, err := t.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.TeamType), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Take() (*models.TeamType, error) {
|
||||
if result, err := t.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.TeamType), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Last() (*models.TeamType, error) {
|
||||
if result, err := t.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.TeamType), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Find() ([]*models.TeamType, error) {
|
||||
result, err := t.DO.Find()
|
||||
return result.([]*models.TeamType), err
|
||||
}
|
||||
|
||||
func (t teamTypeDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.TeamType, err error) {
|
||||
buf := make([]*models.TeamType, 0, batchSize)
|
||||
err = t.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (t teamTypeDo) FindInBatches(result *[]*models.TeamType, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return t.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Attrs(attrs ...field.AssignExpr) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Assign(attrs ...field.AssignExpr) ITeamTypeDo {
|
||||
return t.withDO(t.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Joins(fields ...field.RelationField) ITeamTypeDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Joins(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Preload(fields ...field.RelationField) ITeamTypeDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Preload(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t teamTypeDo) FirstOrInit() (*models.TeamType, error) {
|
||||
if result, err := t.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.TeamType), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t teamTypeDo) FirstOrCreate() (*models.TeamType, error) {
|
||||
if result, err := t.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.TeamType), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t teamTypeDo) FindByPage(offset int, limit int) (result []*models.TeamType, count int64, err error) {
|
||||
result, err = t.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = t.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (t teamTypeDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = t.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = t.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Scan(result interface{}) (err error) {
|
||||
return t.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (t teamTypeDo) Delete(models ...*models.TeamType) (result gen.ResultInfo, err error) {
|
||||
return t.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (t *teamTypeDo) withDO(do gen.Dao) *teamTypeDo {
|
||||
t.DO = *do.(*gen.DO)
|
||||
return t
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func init() {
|
||||
InitializeDB()
|
||||
err := _gen_test_db.AutoMigrate(&models.TeamType{})
|
||||
if err != nil {
|
||||
fmt.Printf("Error: AutoMigrate(&models.TeamType{}) fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_teamTypeQuery(t *testing.T) {
|
||||
teamType := newTeamType(_gen_test_db)
|
||||
teamType = *teamType.As(teamType.TableName())
|
||||
_do := teamType.WithContext(context.Background()).Debug()
|
||||
|
||||
primaryKey := field.NewString(teamType.TableName(), clause.PrimaryKey)
|
||||
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
|
||||
if err != nil {
|
||||
t.Error("clean table <team_types> fail:", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, ok := teamType.GetFieldByName("")
|
||||
if ok {
|
||||
t.Error("GetFieldByName(\"\") from teamType success")
|
||||
}
|
||||
|
||||
err = _do.Create(&models.TeamType{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Save(&models.TeamType{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.CreateInBatches([]*models.TeamType{{}, {}}, 10)
|
||||
if err != nil {
|
||||
t.Error("create item in table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(teamType.ALL).Take()
|
||||
if err != nil {
|
||||
t.Error("Take() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.First()
|
||||
if err != nil {
|
||||
t.Error("First() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Last()
|
||||
if err != nil {
|
||||
t.Error("First() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatch() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*models.TeamType{}, 10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatches() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(teamType.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
|
||||
if err != nil {
|
||||
t.Error("Find() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Distinct(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("select Distinct() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(teamType.ALL).Omit(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("Omit() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Group(primaryKey).Find()
|
||||
if err != nil {
|
||||
t.Error("Group() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
|
||||
if err != nil {
|
||||
t.Error("Scopes() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
_, _, err = _do.FindByPage(0, 1)
|
||||
if err != nil {
|
||||
t.Error("FindByPage() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.ScanByPage(&models.TeamType{}, 0, 1)
|
||||
if err != nil {
|
||||
t.Error("ScanByPage() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
|
||||
if err != nil {
|
||||
t.Error("FirstOrInit() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
|
||||
if err != nil {
|
||||
t.Error("FirstOrCreate() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
var _a _another
|
||||
var _aPK = field.NewString(_a.TableName(), "id")
|
||||
|
||||
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("Join() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("LeftJoin() on table <team_types> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Not().Or().Clauses().Take()
|
||||
if err != nil {
|
||||
t.Error("Not/Or/Clauses on table <team_types> fail:", err)
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,145 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func init() {
|
||||
InitializeDB()
|
||||
err := _gen_test_db.AutoMigrate(&models.WorkArea{})
|
||||
if err != nil {
|
||||
fmt.Printf("Error: AutoMigrate(&models.WorkArea{}) fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_workAreaQuery(t *testing.T) {
|
||||
workArea := newWorkArea(_gen_test_db)
|
||||
workArea = *workArea.As(workArea.TableName())
|
||||
_do := workArea.WithContext(context.Background()).Debug()
|
||||
|
||||
primaryKey := field.NewString(workArea.TableName(), clause.PrimaryKey)
|
||||
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
|
||||
if err != nil {
|
||||
t.Error("clean table <work_areas> fail:", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, ok := workArea.GetFieldByName("")
|
||||
if ok {
|
||||
t.Error("GetFieldByName(\"\") from workArea success")
|
||||
}
|
||||
|
||||
err = _do.Create(&models.WorkArea{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Save(&models.WorkArea{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.CreateInBatches([]*models.WorkArea{{}, {}}, 10)
|
||||
if err != nil {
|
||||
t.Error("create item in table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(workArea.ALL).Take()
|
||||
if err != nil {
|
||||
t.Error("Take() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.First()
|
||||
if err != nil {
|
||||
t.Error("First() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Last()
|
||||
if err != nil {
|
||||
t.Error("First() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatch() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*models.WorkArea{}, 10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatches() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(workArea.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
|
||||
if err != nil {
|
||||
t.Error("Find() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Distinct(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("select Distinct() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(workArea.ALL).Omit(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("Omit() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Group(primaryKey).Find()
|
||||
if err != nil {
|
||||
t.Error("Group() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
|
||||
if err != nil {
|
||||
t.Error("Scopes() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
_, _, err = _do.FindByPage(0, 1)
|
||||
if err != nil {
|
||||
t.Error("FindByPage() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.ScanByPage(&models.WorkArea{}, 0, 1)
|
||||
if err != nil {
|
||||
t.Error("ScanByPage() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
|
||||
if err != nil {
|
||||
t.Error("FirstOrInit() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
|
||||
if err != nil {
|
||||
t.Error("FirstOrCreate() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
var _a _another
|
||||
var _aPK = field.NewString(_a.TableName(), "id")
|
||||
|
||||
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("Join() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("LeftJoin() on table <work_areas> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Not().Or().Clauses().Take()
|
||||
if err != nil {
|
||||
t.Error("Not/Or/Clauses on table <work_areas> fail:", err)
|
||||
}
|
||||
}
|
||||
@@ -1,910 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newWorker(db *gorm.DB, opts ...gen.DOOption) worker {
|
||||
_worker := worker{}
|
||||
|
||||
_worker.workerDo.UseDB(db, opts...)
|
||||
_worker.workerDo.UseModel(&models.Worker{})
|
||||
|
||||
tableName := _worker.workerDo.TableName()
|
||||
_worker.ALL = field.NewAsterisk(tableName)
|
||||
_worker.Id = field.NewUint(tableName, "id")
|
||||
_worker.Name = field.NewString(tableName, "name")
|
||||
_worker.WorkshopId = field.NewUint(tableName, "workshop_id")
|
||||
_worker.Workshop = workerBelongsToWorkshop{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Workshop", "models.Workshop"),
|
||||
WorkAreas: struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Order struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workshops struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Shifts struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas", "models.WorkArea"),
|
||||
Workshop: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.Workshop", "models.Workshop"),
|
||||
},
|
||||
PrepTasks: struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Order struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workshops struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.PrepTasks", "models.PrepTask"),
|
||||
Task: struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Order struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workshops struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.PrepTasks.Task", "models.Task"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.PrepTasks.Task.ProductType", "models.ProductType"),
|
||||
},
|
||||
Order: struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.PrepTasks.Task.Order", "models.Order"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.PrepTasks.Task.Order.ProductType", "models.ProductType"),
|
||||
},
|
||||
Customer: struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.PrepTasks.Task.Order.Customer", "models.Customer"),
|
||||
Orders: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.PrepTasks.Task.Order.Customer.Orders", "models.Order"),
|
||||
},
|
||||
},
|
||||
Tasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.PrepTasks.Task.Order.Tasks", "models.Task"),
|
||||
},
|
||||
},
|
||||
PrepTasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.PrepTasks.Task.PrepTasks", "models.PrepTask"),
|
||||
},
|
||||
Workshops: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.PrepTasks.Task.Workshops", "models.Workshop"),
|
||||
},
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.PrepTasks.WorkArea", "models.WorkArea"),
|
||||
},
|
||||
},
|
||||
Shifts: struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.Shifts", "models.Shift"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.Shifts.ProductType", "models.ProductType"),
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.Shifts.WorkArea", "models.WorkArea"),
|
||||
},
|
||||
},
|
||||
TeamTasks: struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.TeamTasks", "models.TeamTask"),
|
||||
TeamType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.TeamTasks.TeamType", "models.TeamType"),
|
||||
},
|
||||
TeamLeader: struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.TeamTasks.TeamLeader", "models.Worker"),
|
||||
Workshop: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.TeamTasks.TeamLeader.Workshop", "models.Workshop"),
|
||||
},
|
||||
TeamTasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.TeamTasks.TeamLeader.TeamTasks", "models.TeamTask"),
|
||||
},
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.TeamTasks.WorkArea", "models.WorkArea"),
|
||||
},
|
||||
TeamMembers: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.WorkAreas.TeamTasks.TeamMembers", "models.Worker"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Workers: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.Workers", "models.Worker"),
|
||||
},
|
||||
Tasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Workshop.Tasks", "models.Task"),
|
||||
},
|
||||
}
|
||||
|
||||
_worker.TeamTasks = workerManyToManyTeamTasks{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("TeamTasks", "models.TeamTask"),
|
||||
}
|
||||
|
||||
_worker.fillFieldMap()
|
||||
|
||||
return _worker
|
||||
}
|
||||
|
||||
type worker struct {
|
||||
workerDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
Name field.String
|
||||
WorkshopId field.Uint
|
||||
Workshop workerBelongsToWorkshop
|
||||
|
||||
TeamTasks workerManyToManyTeamTasks
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (w worker) Table(newTableName string) *worker {
|
||||
w.workerDo.UseTable(newTableName)
|
||||
return w.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (w worker) As(alias string) *worker {
|
||||
w.workerDo.DO = *(w.workerDo.As(alias).(*gen.DO))
|
||||
return w.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (w *worker) updateTableName(table string) *worker {
|
||||
w.ALL = field.NewAsterisk(table)
|
||||
w.Id = field.NewUint(table, "id")
|
||||
w.Name = field.NewString(table, "name")
|
||||
w.WorkshopId = field.NewUint(table, "workshop_id")
|
||||
|
||||
w.fillFieldMap()
|
||||
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *worker) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := w.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (w *worker) fillFieldMap() {
|
||||
w.fieldMap = make(map[string]field.Expr, 5)
|
||||
w.fieldMap["id"] = w.Id
|
||||
w.fieldMap["name"] = w.Name
|
||||
w.fieldMap["workshop_id"] = w.WorkshopId
|
||||
|
||||
}
|
||||
|
||||
func (w worker) clone(db *gorm.DB) worker {
|
||||
w.workerDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return w
|
||||
}
|
||||
|
||||
func (w worker) replaceDB(db *gorm.DB) worker {
|
||||
w.workerDo.ReplaceDB(db)
|
||||
return w
|
||||
}
|
||||
|
||||
type workerBelongsToWorkshop struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
|
||||
WorkAreas struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Order struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workshops struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Shifts struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Workers struct {
|
||||
field.RelationField
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
func (a workerBelongsToWorkshop) Where(conds ...field.Expr) *workerBelongsToWorkshop {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workerBelongsToWorkshop) WithContext(ctx context.Context) *workerBelongsToWorkshop {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workerBelongsToWorkshop) Session(session *gorm.Session) *workerBelongsToWorkshop {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workerBelongsToWorkshop) Model(m *models.Worker) *workerBelongsToWorkshopTx {
|
||||
return &workerBelongsToWorkshopTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type workerBelongsToWorkshopTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a workerBelongsToWorkshopTx) Find() (result *models.Workshop, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a workerBelongsToWorkshopTx) Append(values ...*models.Workshop) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a workerBelongsToWorkshopTx) Replace(values ...*models.Workshop) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a workerBelongsToWorkshopTx) Delete(values ...*models.Workshop) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a workerBelongsToWorkshopTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a workerBelongsToWorkshopTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type workerManyToManyTeamTasks struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a workerManyToManyTeamTasks) Where(conds ...field.Expr) *workerManyToManyTeamTasks {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workerManyToManyTeamTasks) WithContext(ctx context.Context) *workerManyToManyTeamTasks {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workerManyToManyTeamTasks) Session(session *gorm.Session) *workerManyToManyTeamTasks {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workerManyToManyTeamTasks) Model(m *models.Worker) *workerManyToManyTeamTasksTx {
|
||||
return &workerManyToManyTeamTasksTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type workerManyToManyTeamTasksTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a workerManyToManyTeamTasksTx) Find() (result []*models.TeamTask, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a workerManyToManyTeamTasksTx) Append(values ...*models.TeamTask) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a workerManyToManyTeamTasksTx) Replace(values ...*models.TeamTask) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a workerManyToManyTeamTasksTx) Delete(values ...*models.TeamTask) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a workerManyToManyTeamTasksTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a workerManyToManyTeamTasksTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type workerDo struct{ gen.DO }
|
||||
|
||||
type IWorkerDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IWorkerDo
|
||||
WithContext(ctx context.Context) IWorkerDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IWorkerDo
|
||||
WriteDB() IWorkerDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IWorkerDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IWorkerDo
|
||||
Not(conds ...gen.Condition) IWorkerDo
|
||||
Or(conds ...gen.Condition) IWorkerDo
|
||||
Select(conds ...field.Expr) IWorkerDo
|
||||
Where(conds ...gen.Condition) IWorkerDo
|
||||
Order(conds ...field.Expr) IWorkerDo
|
||||
Distinct(cols ...field.Expr) IWorkerDo
|
||||
Omit(cols ...field.Expr) IWorkerDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IWorkerDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IWorkerDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IWorkerDo
|
||||
Group(cols ...field.Expr) IWorkerDo
|
||||
Having(conds ...gen.Condition) IWorkerDo
|
||||
Limit(limit int) IWorkerDo
|
||||
Offset(offset int) IWorkerDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IWorkerDo
|
||||
Unscoped() IWorkerDo
|
||||
Create(values ...*models.Worker) error
|
||||
CreateInBatches(values []*models.Worker, batchSize int) error
|
||||
Save(values ...*models.Worker) error
|
||||
First() (*models.Worker, error)
|
||||
Take() (*models.Worker, error)
|
||||
Last() (*models.Worker, error)
|
||||
Find() ([]*models.Worker, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Worker, err error)
|
||||
FindInBatches(result *[]*models.Worker, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*models.Worker) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IWorkerDo
|
||||
Assign(attrs ...field.AssignExpr) IWorkerDo
|
||||
Joins(fields ...field.RelationField) IWorkerDo
|
||||
Preload(fields ...field.RelationField) IWorkerDo
|
||||
FirstOrInit() (*models.Worker, error)
|
||||
FirstOrCreate() (*models.Worker, error)
|
||||
FindByPage(offset int, limit int) (result []*models.Worker, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IWorkerDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (w workerDo) Debug() IWorkerDo {
|
||||
return w.withDO(w.DO.Debug())
|
||||
}
|
||||
|
||||
func (w workerDo) WithContext(ctx context.Context) IWorkerDo {
|
||||
return w.withDO(w.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (w workerDo) ReadDB() IWorkerDo {
|
||||
return w.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (w workerDo) WriteDB() IWorkerDo {
|
||||
return w.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (w workerDo) Session(config *gorm.Session) IWorkerDo {
|
||||
return w.withDO(w.DO.Session(config))
|
||||
}
|
||||
|
||||
func (w workerDo) Clauses(conds ...clause.Expression) IWorkerDo {
|
||||
return w.withDO(w.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (w workerDo) Returning(value interface{}, columns ...string) IWorkerDo {
|
||||
return w.withDO(w.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (w workerDo) Not(conds ...gen.Condition) IWorkerDo {
|
||||
return w.withDO(w.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (w workerDo) Or(conds ...gen.Condition) IWorkerDo {
|
||||
return w.withDO(w.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (w workerDo) Select(conds ...field.Expr) IWorkerDo {
|
||||
return w.withDO(w.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (w workerDo) Where(conds ...gen.Condition) IWorkerDo {
|
||||
return w.withDO(w.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (w workerDo) Order(conds ...field.Expr) IWorkerDo {
|
||||
return w.withDO(w.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (w workerDo) Distinct(cols ...field.Expr) IWorkerDo {
|
||||
return w.withDO(w.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (w workerDo) Omit(cols ...field.Expr) IWorkerDo {
|
||||
return w.withDO(w.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (w workerDo) Join(table schema.Tabler, on ...field.Expr) IWorkerDo {
|
||||
return w.withDO(w.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (w workerDo) LeftJoin(table schema.Tabler, on ...field.Expr) IWorkerDo {
|
||||
return w.withDO(w.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (w workerDo) RightJoin(table schema.Tabler, on ...field.Expr) IWorkerDo {
|
||||
return w.withDO(w.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (w workerDo) Group(cols ...field.Expr) IWorkerDo {
|
||||
return w.withDO(w.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (w workerDo) Having(conds ...gen.Condition) IWorkerDo {
|
||||
return w.withDO(w.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (w workerDo) Limit(limit int) IWorkerDo {
|
||||
return w.withDO(w.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (w workerDo) Offset(offset int) IWorkerDo {
|
||||
return w.withDO(w.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (w workerDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IWorkerDo {
|
||||
return w.withDO(w.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (w workerDo) Unscoped() IWorkerDo {
|
||||
return w.withDO(w.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (w workerDo) Create(values ...*models.Worker) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return w.DO.Create(values)
|
||||
}
|
||||
|
||||
func (w workerDo) CreateInBatches(values []*models.Worker, batchSize int) error {
|
||||
return w.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (w workerDo) Save(values ...*models.Worker) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return w.DO.Save(values)
|
||||
}
|
||||
|
||||
func (w workerDo) First() (*models.Worker, error) {
|
||||
if result, err := w.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Worker), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w workerDo) Take() (*models.Worker, error) {
|
||||
if result, err := w.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Worker), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w workerDo) Last() (*models.Worker, error) {
|
||||
if result, err := w.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Worker), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w workerDo) Find() ([]*models.Worker, error) {
|
||||
result, err := w.DO.Find()
|
||||
return result.([]*models.Worker), err
|
||||
}
|
||||
|
||||
func (w workerDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Worker, err error) {
|
||||
buf := make([]*models.Worker, 0, batchSize)
|
||||
err = w.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (w workerDo) FindInBatches(result *[]*models.Worker, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return w.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (w workerDo) Attrs(attrs ...field.AssignExpr) IWorkerDo {
|
||||
return w.withDO(w.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (w workerDo) Assign(attrs ...field.AssignExpr) IWorkerDo {
|
||||
return w.withDO(w.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (w workerDo) Joins(fields ...field.RelationField) IWorkerDo {
|
||||
for _, _f := range fields {
|
||||
w = *w.withDO(w.DO.Joins(_f))
|
||||
}
|
||||
return &w
|
||||
}
|
||||
|
||||
func (w workerDo) Preload(fields ...field.RelationField) IWorkerDo {
|
||||
for _, _f := range fields {
|
||||
w = *w.withDO(w.DO.Preload(_f))
|
||||
}
|
||||
return &w
|
||||
}
|
||||
|
||||
func (w workerDo) FirstOrInit() (*models.Worker, error) {
|
||||
if result, err := w.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Worker), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w workerDo) FirstOrCreate() (*models.Worker, error) {
|
||||
if result, err := w.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Worker), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w workerDo) FindByPage(offset int, limit int) (result []*models.Worker, count int64, err error) {
|
||||
result, err = w.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = w.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (w workerDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = w.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = w.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (w workerDo) Scan(result interface{}) (err error) {
|
||||
return w.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (w workerDo) Delete(models ...*models.Worker) (result gen.ResultInfo, err error) {
|
||||
return w.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (w *workerDo) withDO(do gen.Dao) *workerDo {
|
||||
w.DO = *do.(*gen.DO)
|
||||
return w
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func init() {
|
||||
InitializeDB()
|
||||
err := _gen_test_db.AutoMigrate(&models.Worker{})
|
||||
if err != nil {
|
||||
fmt.Printf("Error: AutoMigrate(&models.Worker{}) fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_workerQuery(t *testing.T) {
|
||||
worker := newWorker(_gen_test_db)
|
||||
worker = *worker.As(worker.TableName())
|
||||
_do := worker.WithContext(context.Background()).Debug()
|
||||
|
||||
primaryKey := field.NewString(worker.TableName(), clause.PrimaryKey)
|
||||
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
|
||||
if err != nil {
|
||||
t.Error("clean table <workers> fail:", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, ok := worker.GetFieldByName("")
|
||||
if ok {
|
||||
t.Error("GetFieldByName(\"\") from worker success")
|
||||
}
|
||||
|
||||
err = _do.Create(&models.Worker{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <workers> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Save(&models.Worker{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <workers> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.CreateInBatches([]*models.Worker{{}, {}}, 10)
|
||||
if err != nil {
|
||||
t.Error("create item in table <workers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(worker.ALL).Take()
|
||||
if err != nil {
|
||||
t.Error("Take() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.First()
|
||||
if err != nil {
|
||||
t.Error("First() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Last()
|
||||
if err != nil {
|
||||
t.Error("First() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatch() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*models.Worker{}, 10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatches() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(worker.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
|
||||
if err != nil {
|
||||
t.Error("Find() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Distinct(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("select Distinct() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(worker.ALL).Omit(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("Omit() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Group(primaryKey).Find()
|
||||
if err != nil {
|
||||
t.Error("Group() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
|
||||
if err != nil {
|
||||
t.Error("Scopes() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
_, _, err = _do.FindByPage(0, 1)
|
||||
if err != nil {
|
||||
t.Error("FindByPage() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.ScanByPage(&models.Worker{}, 0, 1)
|
||||
if err != nil {
|
||||
t.Error("ScanByPage() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
|
||||
if err != nil {
|
||||
t.Error("FirstOrInit() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
|
||||
if err != nil {
|
||||
t.Error("FirstOrCreate() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
var _a _another
|
||||
var _aPK = field.NewString(_a.TableName(), "id")
|
||||
|
||||
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("Join() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("LeftJoin() on table <workers> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Not().Or().Clauses().Take()
|
||||
if err != nil {
|
||||
t.Error("Not/Or/Clauses on table <workers> fail:", err)
|
||||
}
|
||||
}
|
||||
@@ -1,964 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newWorkshop(db *gorm.DB, opts ...gen.DOOption) workshop {
|
||||
_workshop := workshop{}
|
||||
|
||||
_workshop.workshopDo.UseDB(db, opts...)
|
||||
_workshop.workshopDo.UseModel(&models.Workshop{})
|
||||
|
||||
tableName := _workshop.workshopDo.TableName()
|
||||
_workshop.ALL = field.NewAsterisk(tableName)
|
||||
_workshop.Id = field.NewUint(tableName, "id")
|
||||
_workshop.Name = field.NewString(tableName, "name")
|
||||
_workshop.WorkAreas = workshopHasManyWorkAreas{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("WorkAreas", "models.WorkArea"),
|
||||
Workshop: struct {
|
||||
field.RelationField
|
||||
WorkAreas struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workers struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Order struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Workshops struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop", "models.Workshop"),
|
||||
WorkAreas: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.WorkAreas", "models.WorkArea"),
|
||||
},
|
||||
Workers: struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Workers", "models.Worker"),
|
||||
Workshop: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Workers.Workshop", "models.Workshop"),
|
||||
},
|
||||
TeamTasks: struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Workers.TeamTasks", "models.TeamTask"),
|
||||
TeamType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Workers.TeamTasks.TeamType", "models.TeamType"),
|
||||
},
|
||||
TeamLeader: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Workers.TeamTasks.TeamLeader", "models.Worker"),
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Workers.TeamTasks.WorkArea", "models.WorkArea"),
|
||||
},
|
||||
TeamMembers: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Workers.TeamTasks.TeamMembers", "models.Worker"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Tasks: struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Order struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Workshops struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Tasks", "models.Task"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Tasks.ProductType", "models.ProductType"),
|
||||
},
|
||||
Order: struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Tasks.Order", "models.Order"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Tasks.Order.ProductType", "models.ProductType"),
|
||||
},
|
||||
Customer: struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Tasks.Order.Customer", "models.Customer"),
|
||||
Orders: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Tasks.Order.Customer.Orders", "models.Order"),
|
||||
},
|
||||
},
|
||||
Tasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Tasks.Order.Tasks", "models.Task"),
|
||||
},
|
||||
},
|
||||
PrepTasks: struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Tasks.PrepTasks", "models.PrepTask"),
|
||||
Task: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Tasks.PrepTasks.Task", "models.Task"),
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Tasks.PrepTasks.WorkArea", "models.WorkArea"),
|
||||
},
|
||||
},
|
||||
Workshops: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Workshop.Tasks.Workshops", "models.Workshop"),
|
||||
},
|
||||
},
|
||||
},
|
||||
PrepTasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.PrepTasks", "models.PrepTask"),
|
||||
},
|
||||
Shifts: struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Shifts", "models.Shift"),
|
||||
ProductType: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Shifts.ProductType", "models.ProductType"),
|
||||
},
|
||||
WorkArea: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.Shifts.WorkArea", "models.WorkArea"),
|
||||
},
|
||||
},
|
||||
TeamTasks: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("WorkAreas.TeamTasks", "models.TeamTask"),
|
||||
},
|
||||
}
|
||||
|
||||
_workshop.Workers = workshopHasManyWorkers{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Workers", "models.Worker"),
|
||||
}
|
||||
|
||||
_workshop.Tasks = workshopManyToManyTasks{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Tasks", "models.Task"),
|
||||
}
|
||||
|
||||
_workshop.fillFieldMap()
|
||||
|
||||
return _workshop
|
||||
}
|
||||
|
||||
type workshop struct {
|
||||
workshopDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
Name field.String
|
||||
WorkAreas workshopHasManyWorkAreas
|
||||
|
||||
Workers workshopHasManyWorkers
|
||||
|
||||
Tasks workshopManyToManyTasks
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (w workshop) Table(newTableName string) *workshop {
|
||||
w.workshopDo.UseTable(newTableName)
|
||||
return w.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (w workshop) As(alias string) *workshop {
|
||||
w.workshopDo.DO = *(w.workshopDo.As(alias).(*gen.DO))
|
||||
return w.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (w *workshop) updateTableName(table string) *workshop {
|
||||
w.ALL = field.NewAsterisk(table)
|
||||
w.Id = field.NewUint(table, "id")
|
||||
w.Name = field.NewString(table, "name")
|
||||
|
||||
w.fillFieldMap()
|
||||
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *workshop) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := w.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (w *workshop) fillFieldMap() {
|
||||
w.fieldMap = make(map[string]field.Expr, 5)
|
||||
w.fieldMap["id"] = w.Id
|
||||
w.fieldMap["name"] = w.Name
|
||||
|
||||
}
|
||||
|
||||
func (w workshop) clone(db *gorm.DB) workshop {
|
||||
w.workshopDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return w
|
||||
}
|
||||
|
||||
func (w workshop) replaceDB(db *gorm.DB) workshop {
|
||||
w.workshopDo.ReplaceDB(db)
|
||||
return w
|
||||
}
|
||||
|
||||
type workshopHasManyWorkAreas struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
WorkAreas struct {
|
||||
field.RelationField
|
||||
}
|
||||
Workers struct {
|
||||
field.RelationField
|
||||
Workshop struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
TeamType struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamLeader struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
TeamMembers struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Order struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
Customer struct {
|
||||
field.RelationField
|
||||
Orders struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Tasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
Task struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Workshops struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
PrepTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
Shifts struct {
|
||||
field.RelationField
|
||||
ProductType struct {
|
||||
field.RelationField
|
||||
}
|
||||
WorkArea struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
TeamTasks struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkAreas) Where(conds ...field.Expr) *workshopHasManyWorkAreas {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkAreas) WithContext(ctx context.Context) *workshopHasManyWorkAreas {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkAreas) Session(session *gorm.Session) *workshopHasManyWorkAreas {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkAreas) Model(m *models.Workshop) *workshopHasManyWorkAreasTx {
|
||||
return &workshopHasManyWorkAreasTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type workshopHasManyWorkAreasTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a workshopHasManyWorkAreasTx) Find() (result []*models.WorkArea, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkAreasTx) Append(values ...*models.WorkArea) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkAreasTx) Replace(values ...*models.WorkArea) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkAreasTx) Delete(values ...*models.WorkArea) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkAreasTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkAreasTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type workshopHasManyWorkers struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkers) Where(conds ...field.Expr) *workshopHasManyWorkers {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkers) WithContext(ctx context.Context) *workshopHasManyWorkers {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkers) Session(session *gorm.Session) *workshopHasManyWorkers {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkers) Model(m *models.Workshop) *workshopHasManyWorkersTx {
|
||||
return &workshopHasManyWorkersTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type workshopHasManyWorkersTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a workshopHasManyWorkersTx) Find() (result []*models.Worker, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkersTx) Append(values ...*models.Worker) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkersTx) Replace(values ...*models.Worker) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkersTx) Delete(values ...*models.Worker) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkersTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a workshopHasManyWorkersTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type workshopManyToManyTasks struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a workshopManyToManyTasks) Where(conds ...field.Expr) *workshopManyToManyTasks {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workshopManyToManyTasks) WithContext(ctx context.Context) *workshopManyToManyTasks {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workshopManyToManyTasks) Session(session *gorm.Session) *workshopManyToManyTasks {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a workshopManyToManyTasks) Model(m *models.Workshop) *workshopManyToManyTasksTx {
|
||||
return &workshopManyToManyTasksTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type workshopManyToManyTasksTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a workshopManyToManyTasksTx) Find() (result []*models.Task, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a workshopManyToManyTasksTx) Append(values ...*models.Task) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a workshopManyToManyTasksTx) Replace(values ...*models.Task) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a workshopManyToManyTasksTx) Delete(values ...*models.Task) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a workshopManyToManyTasksTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a workshopManyToManyTasksTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type workshopDo struct{ gen.DO }
|
||||
|
||||
type IWorkshopDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IWorkshopDo
|
||||
WithContext(ctx context.Context) IWorkshopDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IWorkshopDo
|
||||
WriteDB() IWorkshopDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IWorkshopDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IWorkshopDo
|
||||
Not(conds ...gen.Condition) IWorkshopDo
|
||||
Or(conds ...gen.Condition) IWorkshopDo
|
||||
Select(conds ...field.Expr) IWorkshopDo
|
||||
Where(conds ...gen.Condition) IWorkshopDo
|
||||
Order(conds ...field.Expr) IWorkshopDo
|
||||
Distinct(cols ...field.Expr) IWorkshopDo
|
||||
Omit(cols ...field.Expr) IWorkshopDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IWorkshopDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IWorkshopDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IWorkshopDo
|
||||
Group(cols ...field.Expr) IWorkshopDo
|
||||
Having(conds ...gen.Condition) IWorkshopDo
|
||||
Limit(limit int) IWorkshopDo
|
||||
Offset(offset int) IWorkshopDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IWorkshopDo
|
||||
Unscoped() IWorkshopDo
|
||||
Create(values ...*models.Workshop) error
|
||||
CreateInBatches(values []*models.Workshop, batchSize int) error
|
||||
Save(values ...*models.Workshop) error
|
||||
First() (*models.Workshop, error)
|
||||
Take() (*models.Workshop, error)
|
||||
Last() (*models.Workshop, error)
|
||||
Find() ([]*models.Workshop, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Workshop, err error)
|
||||
FindInBatches(result *[]*models.Workshop, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*models.Workshop) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IWorkshopDo
|
||||
Assign(attrs ...field.AssignExpr) IWorkshopDo
|
||||
Joins(fields ...field.RelationField) IWorkshopDo
|
||||
Preload(fields ...field.RelationField) IWorkshopDo
|
||||
FirstOrInit() (*models.Workshop, error)
|
||||
FirstOrCreate() (*models.Workshop, error)
|
||||
FindByPage(offset int, limit int) (result []*models.Workshop, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IWorkshopDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (w workshopDo) Debug() IWorkshopDo {
|
||||
return w.withDO(w.DO.Debug())
|
||||
}
|
||||
|
||||
func (w workshopDo) WithContext(ctx context.Context) IWorkshopDo {
|
||||
return w.withDO(w.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (w workshopDo) ReadDB() IWorkshopDo {
|
||||
return w.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (w workshopDo) WriteDB() IWorkshopDo {
|
||||
return w.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (w workshopDo) Session(config *gorm.Session) IWorkshopDo {
|
||||
return w.withDO(w.DO.Session(config))
|
||||
}
|
||||
|
||||
func (w workshopDo) Clauses(conds ...clause.Expression) IWorkshopDo {
|
||||
return w.withDO(w.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Returning(value interface{}, columns ...string) IWorkshopDo {
|
||||
return w.withDO(w.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Not(conds ...gen.Condition) IWorkshopDo {
|
||||
return w.withDO(w.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Or(conds ...gen.Condition) IWorkshopDo {
|
||||
return w.withDO(w.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Select(conds ...field.Expr) IWorkshopDo {
|
||||
return w.withDO(w.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Where(conds ...gen.Condition) IWorkshopDo {
|
||||
return w.withDO(w.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Order(conds ...field.Expr) IWorkshopDo {
|
||||
return w.withDO(w.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Distinct(cols ...field.Expr) IWorkshopDo {
|
||||
return w.withDO(w.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Omit(cols ...field.Expr) IWorkshopDo {
|
||||
return w.withDO(w.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Join(table schema.Tabler, on ...field.Expr) IWorkshopDo {
|
||||
return w.withDO(w.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (w workshopDo) LeftJoin(table schema.Tabler, on ...field.Expr) IWorkshopDo {
|
||||
return w.withDO(w.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (w workshopDo) RightJoin(table schema.Tabler, on ...field.Expr) IWorkshopDo {
|
||||
return w.withDO(w.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Group(cols ...field.Expr) IWorkshopDo {
|
||||
return w.withDO(w.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Having(conds ...gen.Condition) IWorkshopDo {
|
||||
return w.withDO(w.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Limit(limit int) IWorkshopDo {
|
||||
return w.withDO(w.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (w workshopDo) Offset(offset int) IWorkshopDo {
|
||||
return w.withDO(w.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (w workshopDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IWorkshopDo {
|
||||
return w.withDO(w.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Unscoped() IWorkshopDo {
|
||||
return w.withDO(w.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (w workshopDo) Create(values ...*models.Workshop) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return w.DO.Create(values)
|
||||
}
|
||||
|
||||
func (w workshopDo) CreateInBatches(values []*models.Workshop, batchSize int) error {
|
||||
return w.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (w workshopDo) Save(values ...*models.Workshop) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return w.DO.Save(values)
|
||||
}
|
||||
|
||||
func (w workshopDo) First() (*models.Workshop, error) {
|
||||
if result, err := w.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Workshop), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w workshopDo) Take() (*models.Workshop, error) {
|
||||
if result, err := w.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Workshop), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w workshopDo) Last() (*models.Workshop, error) {
|
||||
if result, err := w.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Workshop), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w workshopDo) Find() ([]*models.Workshop, error) {
|
||||
result, err := w.DO.Find()
|
||||
return result.([]*models.Workshop), err
|
||||
}
|
||||
|
||||
func (w workshopDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Workshop, err error) {
|
||||
buf := make([]*models.Workshop, 0, batchSize)
|
||||
err = w.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (w workshopDo) FindInBatches(result *[]*models.Workshop, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return w.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (w workshopDo) Attrs(attrs ...field.AssignExpr) IWorkshopDo {
|
||||
return w.withDO(w.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Assign(attrs ...field.AssignExpr) IWorkshopDo {
|
||||
return w.withDO(w.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (w workshopDo) Joins(fields ...field.RelationField) IWorkshopDo {
|
||||
for _, _f := range fields {
|
||||
w = *w.withDO(w.DO.Joins(_f))
|
||||
}
|
||||
return &w
|
||||
}
|
||||
|
||||
func (w workshopDo) Preload(fields ...field.RelationField) IWorkshopDo {
|
||||
for _, _f := range fields {
|
||||
w = *w.withDO(w.DO.Preload(_f))
|
||||
}
|
||||
return &w
|
||||
}
|
||||
|
||||
func (w workshopDo) FirstOrInit() (*models.Workshop, error) {
|
||||
if result, err := w.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Workshop), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w workshopDo) FirstOrCreate() (*models.Workshop, error) {
|
||||
if result, err := w.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Workshop), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w workshopDo) FindByPage(offset int, limit int) (result []*models.Workshop, count int64, err error) {
|
||||
result, err = w.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = w.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (w workshopDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = w.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = w.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (w workshopDo) Scan(result interface{}) (err error) {
|
||||
return w.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (w workshopDo) Delete(models ...*models.Workshop) (result gen.ResultInfo, err error) {
|
||||
return w.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (w *workshopDo) withDO(do gen.Dao) *workshopDo {
|
||||
w.DO = *do.(*gen.DO)
|
||||
return w
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"app/internal/models"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func init() {
|
||||
InitializeDB()
|
||||
err := _gen_test_db.AutoMigrate(&models.Workshop{})
|
||||
if err != nil {
|
||||
fmt.Printf("Error: AutoMigrate(&models.Workshop{}) fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_workshopQuery(t *testing.T) {
|
||||
workshop := newWorkshop(_gen_test_db)
|
||||
workshop = *workshop.As(workshop.TableName())
|
||||
_do := workshop.WithContext(context.Background()).Debug()
|
||||
|
||||
primaryKey := field.NewString(workshop.TableName(), clause.PrimaryKey)
|
||||
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
|
||||
if err != nil {
|
||||
t.Error("clean table <workshops> fail:", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, ok := workshop.GetFieldByName("")
|
||||
if ok {
|
||||
t.Error("GetFieldByName(\"\") from workshop success")
|
||||
}
|
||||
|
||||
err = _do.Create(&models.Workshop{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Save(&models.Workshop{})
|
||||
if err != nil {
|
||||
t.Error("create item in table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.CreateInBatches([]*models.Workshop{{}, {}}, 10)
|
||||
if err != nil {
|
||||
t.Error("create item in table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(workshop.ALL).Take()
|
||||
if err != nil {
|
||||
t.Error("Take() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.First()
|
||||
if err != nil {
|
||||
t.Error("First() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Last()
|
||||
if err != nil {
|
||||
t.Error("First() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatch() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*models.Workshop{}, 10, func(tx gen.Dao, batch int) error { return nil })
|
||||
if err != nil {
|
||||
t.Error("FindInBatches() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(workshop.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
|
||||
if err != nil {
|
||||
t.Error("Find() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Distinct(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("select Distinct() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Select(workshop.ALL).Omit(primaryKey).Take()
|
||||
if err != nil {
|
||||
t.Error("Omit() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Group(primaryKey).Find()
|
||||
if err != nil {
|
||||
t.Error("Group() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
|
||||
if err != nil {
|
||||
t.Error("Scopes() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
_, _, err = _do.FindByPage(0, 1)
|
||||
if err != nil {
|
||||
t.Error("FindByPage() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.ScanByPage(&models.Workshop{}, 0, 1)
|
||||
if err != nil {
|
||||
t.Error("ScanByPage() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
|
||||
if err != nil {
|
||||
t.Error("FirstOrInit() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
|
||||
if err != nil {
|
||||
t.Error("FirstOrCreate() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
var _a _another
|
||||
var _aPK = field.NewString(_a.TableName(), "id")
|
||||
|
||||
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("Join() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Error("LeftJoin() on table <workshops> fail:", err)
|
||||
}
|
||||
|
||||
_, err = _do.Not().Or().Clauses().Take()
|
||||
if err != nil {
|
||||
t.Error("Not/Or/Clauses on table <workshops> fail:", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user