352 lines
8.7 KiB
Go
352 lines
8.7 KiB
Go
// 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 query
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
"gorm.io/gorm/schema"
|
|
|
|
"gorm.io/gen"
|
|
"gorm.io/gen/field"
|
|
|
|
"gorm.io/plugin/dbresolver"
|
|
|
|
"go_backend/internal/model"
|
|
)
|
|
|
|
func newPerson(db *gorm.DB, opts ...gen.DOOption) person {
|
|
_person := person{}
|
|
|
|
_person.personDo.UseDB(db, opts...)
|
|
_person.personDo.UseModel(&model.Person{})
|
|
|
|
tableName := _person.personDo.TableName()
|
|
_person.ALL = field.NewAsterisk(tableName)
|
|
_person.ID = field.NewInt32(tableName, "id")
|
|
_person.PersonType = field.NewInt32(tableName, "person_type")
|
|
_person.PersonPicURL = field.NewString(tableName, "person_pic_url")
|
|
_person.PersonName = field.NewString(tableName, "person_name")
|
|
_person.IsDeleted = field.NewBool(tableName, "is_deleted")
|
|
_person.CreateTime = field.NewTime(tableName, "create_time")
|
|
_person.UpdateTime = field.NewTime(tableName, "update_time")
|
|
|
|
_person.fillFieldMap()
|
|
|
|
return _person
|
|
}
|
|
|
|
type person struct {
|
|
personDo personDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.Int32
|
|
PersonType field.Int32
|
|
PersonPicURL field.String
|
|
PersonName field.String
|
|
IsDeleted field.Bool
|
|
CreateTime field.Time
|
|
UpdateTime field.Time
|
|
|
|
fieldMap map[string]field.Expr
|
|
}
|
|
|
|
func (p person) Table(newTableName string) *person {
|
|
p.personDo.UseTable(newTableName)
|
|
return p.updateTableName(newTableName)
|
|
}
|
|
|
|
func (p person) As(alias string) *person {
|
|
p.personDo.DO = *(p.personDo.As(alias).(*gen.DO))
|
|
return p.updateTableName(alias)
|
|
}
|
|
|
|
func (p *person) updateTableName(table string) *person {
|
|
p.ALL = field.NewAsterisk(table)
|
|
p.ID = field.NewInt32(table, "id")
|
|
p.PersonType = field.NewInt32(table, "person_type")
|
|
p.PersonPicURL = field.NewString(table, "person_pic_url")
|
|
p.PersonName = field.NewString(table, "person_name")
|
|
p.IsDeleted = field.NewBool(table, "is_deleted")
|
|
p.CreateTime = field.NewTime(table, "create_time")
|
|
p.UpdateTime = field.NewTime(table, "update_time")
|
|
|
|
p.fillFieldMap()
|
|
|
|
return p
|
|
}
|
|
|
|
func (p *person) WithContext(ctx context.Context) *personDo { return p.personDo.WithContext(ctx) }
|
|
|
|
func (p person) TableName() string { return p.personDo.TableName() }
|
|
|
|
func (p person) Alias() string { return p.personDo.Alias() }
|
|
|
|
func (p person) Columns(cols ...field.Expr) gen.Columns { return p.personDo.Columns(cols...) }
|
|
|
|
func (p *person) 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 *person) fillFieldMap() {
|
|
p.fieldMap = make(map[string]field.Expr, 7)
|
|
p.fieldMap["id"] = p.ID
|
|
p.fieldMap["person_type"] = p.PersonType
|
|
p.fieldMap["person_pic_url"] = p.PersonPicURL
|
|
p.fieldMap["person_name"] = p.PersonName
|
|
p.fieldMap["is_deleted"] = p.IsDeleted
|
|
p.fieldMap["create_time"] = p.CreateTime
|
|
p.fieldMap["update_time"] = p.UpdateTime
|
|
}
|
|
|
|
func (p person) clone(db *gorm.DB) person {
|
|
p.personDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
return p
|
|
}
|
|
|
|
func (p person) replaceDB(db *gorm.DB) person {
|
|
p.personDo.ReplaceDB(db)
|
|
return p
|
|
}
|
|
|
|
type personDo struct{ gen.DO }
|
|
|
|
func (p personDo) Debug() *personDo {
|
|
return p.withDO(p.DO.Debug())
|
|
}
|
|
|
|
func (p personDo) WithContext(ctx context.Context) *personDo {
|
|
return p.withDO(p.DO.WithContext(ctx))
|
|
}
|
|
|
|
func (p personDo) ReadDB() *personDo {
|
|
return p.Clauses(dbresolver.Read)
|
|
}
|
|
|
|
func (p personDo) WriteDB() *personDo {
|
|
return p.Clauses(dbresolver.Write)
|
|
}
|
|
|
|
func (p personDo) Session(config *gorm.Session) *personDo {
|
|
return p.withDO(p.DO.Session(config))
|
|
}
|
|
|
|
func (p personDo) Clauses(conds ...clause.Expression) *personDo {
|
|
return p.withDO(p.DO.Clauses(conds...))
|
|
}
|
|
|
|
func (p personDo) Returning(value interface{}, columns ...string) *personDo {
|
|
return p.withDO(p.DO.Returning(value, columns...))
|
|
}
|
|
|
|
func (p personDo) Not(conds ...gen.Condition) *personDo {
|
|
return p.withDO(p.DO.Not(conds...))
|
|
}
|
|
|
|
func (p personDo) Or(conds ...gen.Condition) *personDo {
|
|
return p.withDO(p.DO.Or(conds...))
|
|
}
|
|
|
|
func (p personDo) Select(conds ...field.Expr) *personDo {
|
|
return p.withDO(p.DO.Select(conds...))
|
|
}
|
|
|
|
func (p personDo) Where(conds ...gen.Condition) *personDo {
|
|
return p.withDO(p.DO.Where(conds...))
|
|
}
|
|
|
|
func (p personDo) Order(conds ...field.Expr) *personDo {
|
|
return p.withDO(p.DO.Order(conds...))
|
|
}
|
|
|
|
func (p personDo) Distinct(cols ...field.Expr) *personDo {
|
|
return p.withDO(p.DO.Distinct(cols...))
|
|
}
|
|
|
|
func (p personDo) Omit(cols ...field.Expr) *personDo {
|
|
return p.withDO(p.DO.Omit(cols...))
|
|
}
|
|
|
|
func (p personDo) Join(table schema.Tabler, on ...field.Expr) *personDo {
|
|
return p.withDO(p.DO.Join(table, on...))
|
|
}
|
|
|
|
func (p personDo) LeftJoin(table schema.Tabler, on ...field.Expr) *personDo {
|
|
return p.withDO(p.DO.LeftJoin(table, on...))
|
|
}
|
|
|
|
func (p personDo) RightJoin(table schema.Tabler, on ...field.Expr) *personDo {
|
|
return p.withDO(p.DO.RightJoin(table, on...))
|
|
}
|
|
|
|
func (p personDo) Group(cols ...field.Expr) *personDo {
|
|
return p.withDO(p.DO.Group(cols...))
|
|
}
|
|
|
|
func (p personDo) Having(conds ...gen.Condition) *personDo {
|
|
return p.withDO(p.DO.Having(conds...))
|
|
}
|
|
|
|
func (p personDo) Limit(limit int) *personDo {
|
|
return p.withDO(p.DO.Limit(limit))
|
|
}
|
|
|
|
func (p personDo) Offset(offset int) *personDo {
|
|
return p.withDO(p.DO.Offset(offset))
|
|
}
|
|
|
|
func (p personDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *personDo {
|
|
return p.withDO(p.DO.Scopes(funcs...))
|
|
}
|
|
|
|
func (p personDo) Unscoped() *personDo {
|
|
return p.withDO(p.DO.Unscoped())
|
|
}
|
|
|
|
func (p personDo) Create(values ...*model.Person) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return p.DO.Create(values)
|
|
}
|
|
|
|
func (p personDo) CreateInBatches(values []*model.Person, 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 personDo) Save(values ...*model.Person) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return p.DO.Save(values)
|
|
}
|
|
|
|
func (p personDo) First() (*model.Person, error) {
|
|
if result, err := p.DO.First(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*model.Person), nil
|
|
}
|
|
}
|
|
|
|
func (p personDo) Take() (*model.Person, error) {
|
|
if result, err := p.DO.Take(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*model.Person), nil
|
|
}
|
|
}
|
|
|
|
func (p personDo) Last() (*model.Person, error) {
|
|
if result, err := p.DO.Last(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*model.Person), nil
|
|
}
|
|
}
|
|
|
|
func (p personDo) Find() ([]*model.Person, error) {
|
|
result, err := p.DO.Find()
|
|
return result.([]*model.Person), err
|
|
}
|
|
|
|
func (p personDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Person, err error) {
|
|
buf := make([]*model.Person, 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 personDo) FindInBatches(result *[]*model.Person, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
return p.DO.FindInBatches(result, batchSize, fc)
|
|
}
|
|
|
|
func (p personDo) Attrs(attrs ...field.AssignExpr) *personDo {
|
|
return p.withDO(p.DO.Attrs(attrs...))
|
|
}
|
|
|
|
func (p personDo) Assign(attrs ...field.AssignExpr) *personDo {
|
|
return p.withDO(p.DO.Assign(attrs...))
|
|
}
|
|
|
|
func (p personDo) Joins(fields ...field.RelationField) *personDo {
|
|
for _, _f := range fields {
|
|
p = *p.withDO(p.DO.Joins(_f))
|
|
}
|
|
return &p
|
|
}
|
|
|
|
func (p personDo) Preload(fields ...field.RelationField) *personDo {
|
|
for _, _f := range fields {
|
|
p = *p.withDO(p.DO.Preload(_f))
|
|
}
|
|
return &p
|
|
}
|
|
|
|
func (p personDo) FirstOrInit() (*model.Person, error) {
|
|
if result, err := p.DO.FirstOrInit(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*model.Person), nil
|
|
}
|
|
}
|
|
|
|
func (p personDo) FirstOrCreate() (*model.Person, error) {
|
|
if result, err := p.DO.FirstOrCreate(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*model.Person), nil
|
|
}
|
|
}
|
|
|
|
func (p personDo) FindByPage(offset int, limit int) (result []*model.Person, 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 personDo) 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 personDo) Scan(result interface{}) (err error) {
|
|
return p.DO.Scan(result)
|
|
}
|
|
|
|
func (p personDo) Delete(models ...*model.Person) (result gen.ResultInfo, err error) {
|
|
return p.DO.Delete(models)
|
|
}
|
|
|
|
func (p *personDo) withDO(do gen.Dao) *personDo {
|
|
p.DO = *do.(*gen.DO)
|
|
return p
|
|
}
|