mirror of https://github.com/go-sonic/sonic.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
346 lines
8.5 KiB
Go
346 lines
8.5 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 dal
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gorm.io/gen"
|
|
"gorm.io/gen/field"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
"gorm.io/gorm/schema"
|
|
"gorm.io/plugin/dbresolver"
|
|
|
|
"github.com/go-sonic/sonic/model/entity"
|
|
)
|
|
|
|
func newOption(db *gorm.DB, opts ...gen.DOOption) option {
|
|
_option := option{}
|
|
|
|
_option.optionDo.UseDB(db, opts...)
|
|
_option.optionDo.UseModel(&entity.Option{})
|
|
|
|
tableName := _option.optionDo.TableName()
|
|
_option.ALL = field.NewAsterisk(tableName)
|
|
_option.ID = field.NewInt32(tableName, "id")
|
|
_option.CreateTime = field.NewTime(tableName, "create_time")
|
|
_option.UpdateTime = field.NewTime(tableName, "update_time")
|
|
_option.OptionKey = field.NewString(tableName, "option_key")
|
|
_option.Type = field.NewField(tableName, "type")
|
|
_option.OptionValue = field.NewString(tableName, "option_value")
|
|
|
|
_option.fillFieldMap()
|
|
|
|
return _option
|
|
}
|
|
|
|
type option struct {
|
|
optionDo optionDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.Int32
|
|
CreateTime field.Time
|
|
UpdateTime field.Time
|
|
OptionKey field.String
|
|
Type field.Field
|
|
OptionValue field.String
|
|
|
|
fieldMap map[string]field.Expr
|
|
}
|
|
|
|
func (o option) Table(newTableName string) *option {
|
|
o.optionDo.UseTable(newTableName)
|
|
return o.updateTableName(newTableName)
|
|
}
|
|
|
|
func (o option) As(alias string) *option {
|
|
o.optionDo.DO = *(o.optionDo.As(alias).(*gen.DO))
|
|
return o.updateTableName(alias)
|
|
}
|
|
|
|
func (o *option) updateTableName(table string) *option {
|
|
o.ALL = field.NewAsterisk(table)
|
|
o.ID = field.NewInt32(table, "id")
|
|
o.CreateTime = field.NewTime(table, "create_time")
|
|
o.UpdateTime = field.NewTime(table, "update_time")
|
|
o.OptionKey = field.NewString(table, "option_key")
|
|
o.Type = field.NewField(table, "type")
|
|
o.OptionValue = field.NewString(table, "option_value")
|
|
|
|
o.fillFieldMap()
|
|
|
|
return o
|
|
}
|
|
|
|
func (o *option) WithContext(ctx context.Context) *optionDo { return o.optionDo.WithContext(ctx) }
|
|
|
|
func (o option) TableName() string { return o.optionDo.TableName() }
|
|
|
|
func (o option) Alias() string { return o.optionDo.Alias() }
|
|
|
|
func (o option) Columns(cols ...field.Expr) gen.Columns { return o.optionDo.Columns(cols...) }
|
|
|
|
func (o *option) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|
_f, ok := o.fieldMap[fieldName]
|
|
if !ok || _f == nil {
|
|
return nil, false
|
|
}
|
|
_oe, ok := _f.(field.OrderExpr)
|
|
return _oe, ok
|
|
}
|
|
|
|
func (o *option) fillFieldMap() {
|
|
o.fieldMap = make(map[string]field.Expr, 6)
|
|
o.fieldMap["id"] = o.ID
|
|
o.fieldMap["create_time"] = o.CreateTime
|
|
o.fieldMap["update_time"] = o.UpdateTime
|
|
o.fieldMap["option_key"] = o.OptionKey
|
|
o.fieldMap["type"] = o.Type
|
|
o.fieldMap["option_value"] = o.OptionValue
|
|
}
|
|
|
|
func (o option) clone(db *gorm.DB) option {
|
|
o.optionDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
return o
|
|
}
|
|
|
|
func (o option) replaceDB(db *gorm.DB) option {
|
|
o.optionDo.ReplaceDB(db)
|
|
return o
|
|
}
|
|
|
|
type optionDo struct{ gen.DO }
|
|
|
|
func (o optionDo) Debug() *optionDo {
|
|
return o.withDO(o.DO.Debug())
|
|
}
|
|
|
|
func (o optionDo) WithContext(ctx context.Context) *optionDo {
|
|
return o.withDO(o.DO.WithContext(ctx))
|
|
}
|
|
|
|
func (o optionDo) ReadDB() *optionDo {
|
|
return o.Clauses(dbresolver.Read)
|
|
}
|
|
|
|
func (o optionDo) WriteDB() *optionDo {
|
|
return o.Clauses(dbresolver.Write)
|
|
}
|
|
|
|
func (o optionDo) Session(config *gorm.Session) *optionDo {
|
|
return o.withDO(o.DO.Session(config))
|
|
}
|
|
|
|
func (o optionDo) Clauses(conds ...clause.Expression) *optionDo {
|
|
return o.withDO(o.DO.Clauses(conds...))
|
|
}
|
|
|
|
func (o optionDo) Returning(value interface{}, columns ...string) *optionDo {
|
|
return o.withDO(o.DO.Returning(value, columns...))
|
|
}
|
|
|
|
func (o optionDo) Not(conds ...gen.Condition) *optionDo {
|
|
return o.withDO(o.DO.Not(conds...))
|
|
}
|
|
|
|
func (o optionDo) Or(conds ...gen.Condition) *optionDo {
|
|
return o.withDO(o.DO.Or(conds...))
|
|
}
|
|
|
|
func (o optionDo) Select(conds ...field.Expr) *optionDo {
|
|
return o.withDO(o.DO.Select(conds...))
|
|
}
|
|
|
|
func (o optionDo) Where(conds ...gen.Condition) *optionDo {
|
|
return o.withDO(o.DO.Where(conds...))
|
|
}
|
|
|
|
func (o optionDo) Order(conds ...field.Expr) *optionDo {
|
|
return o.withDO(o.DO.Order(conds...))
|
|
}
|
|
|
|
func (o optionDo) Distinct(cols ...field.Expr) *optionDo {
|
|
return o.withDO(o.DO.Distinct(cols...))
|
|
}
|
|
|
|
func (o optionDo) Omit(cols ...field.Expr) *optionDo {
|
|
return o.withDO(o.DO.Omit(cols...))
|
|
}
|
|
|
|
func (o optionDo) Join(table schema.Tabler, on ...field.Expr) *optionDo {
|
|
return o.withDO(o.DO.Join(table, on...))
|
|
}
|
|
|
|
func (o optionDo) LeftJoin(table schema.Tabler, on ...field.Expr) *optionDo {
|
|
return o.withDO(o.DO.LeftJoin(table, on...))
|
|
}
|
|
|
|
func (o optionDo) RightJoin(table schema.Tabler, on ...field.Expr) *optionDo {
|
|
return o.withDO(o.DO.RightJoin(table, on...))
|
|
}
|
|
|
|
func (o optionDo) Group(cols ...field.Expr) *optionDo {
|
|
return o.withDO(o.DO.Group(cols...))
|
|
}
|
|
|
|
func (o optionDo) Having(conds ...gen.Condition) *optionDo {
|
|
return o.withDO(o.DO.Having(conds...))
|
|
}
|
|
|
|
func (o optionDo) Limit(limit int) *optionDo {
|
|
return o.withDO(o.DO.Limit(limit))
|
|
}
|
|
|
|
func (o optionDo) Offset(offset int) *optionDo {
|
|
return o.withDO(o.DO.Offset(offset))
|
|
}
|
|
|
|
func (o optionDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *optionDo {
|
|
return o.withDO(o.DO.Scopes(funcs...))
|
|
}
|
|
|
|
func (o optionDo) Unscoped() *optionDo {
|
|
return o.withDO(o.DO.Unscoped())
|
|
}
|
|
|
|
func (o optionDo) Create(values ...*entity.Option) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return o.DO.Create(values)
|
|
}
|
|
|
|
func (o optionDo) CreateInBatches(values []*entity.Option, batchSize int) error {
|
|
return o.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 (o optionDo) Save(values ...*entity.Option) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return o.DO.Save(values)
|
|
}
|
|
|
|
func (o optionDo) First() (*entity.Option, error) {
|
|
if result, err := o.DO.First(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Option), nil
|
|
}
|
|
}
|
|
|
|
func (o optionDo) Take() (*entity.Option, error) {
|
|
if result, err := o.DO.Take(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Option), nil
|
|
}
|
|
}
|
|
|
|
func (o optionDo) Last() (*entity.Option, error) {
|
|
if result, err := o.DO.Last(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Option), nil
|
|
}
|
|
}
|
|
|
|
func (o optionDo) Find() ([]*entity.Option, error) {
|
|
result, err := o.DO.Find()
|
|
return result.([]*entity.Option), err
|
|
}
|
|
|
|
func (o optionDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Option, err error) {
|
|
buf := make([]*entity.Option, 0, batchSize)
|
|
err = o.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 (o optionDo) FindInBatches(result *[]*entity.Option, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
return o.DO.FindInBatches(result, batchSize, fc)
|
|
}
|
|
|
|
func (o optionDo) Attrs(attrs ...field.AssignExpr) *optionDo {
|
|
return o.withDO(o.DO.Attrs(attrs...))
|
|
}
|
|
|
|
func (o optionDo) Assign(attrs ...field.AssignExpr) *optionDo {
|
|
return o.withDO(o.DO.Assign(attrs...))
|
|
}
|
|
|
|
func (o optionDo) Joins(fields ...field.RelationField) *optionDo {
|
|
for _, _f := range fields {
|
|
o = *o.withDO(o.DO.Joins(_f))
|
|
}
|
|
return &o
|
|
}
|
|
|
|
func (o optionDo) Preload(fields ...field.RelationField) *optionDo {
|
|
for _, _f := range fields {
|
|
o = *o.withDO(o.DO.Preload(_f))
|
|
}
|
|
return &o
|
|
}
|
|
|
|
func (o optionDo) FirstOrInit() (*entity.Option, error) {
|
|
if result, err := o.DO.FirstOrInit(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Option), nil
|
|
}
|
|
}
|
|
|
|
func (o optionDo) FirstOrCreate() (*entity.Option, error) {
|
|
if result, err := o.DO.FirstOrCreate(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Option), nil
|
|
}
|
|
}
|
|
|
|
func (o optionDo) FindByPage(offset int, limit int) (result []*entity.Option, count int64, err error) {
|
|
result, err = o.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 = o.Offset(-1).Limit(-1).Count()
|
|
return
|
|
}
|
|
|
|
func (o optionDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
|
count, err = o.Count()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = o.Offset(offset).Limit(limit).Scan(result)
|
|
return
|
|
}
|
|
|
|
func (o optionDo) Scan(result interface{}) (err error) {
|
|
return o.DO.Scan(result)
|
|
}
|
|
|
|
func (o optionDo) Delete(models ...*entity.Option) (result gen.ResultInfo, err error) {
|
|
return o.DO.Delete(models)
|
|
}
|
|
|
|
func (o *optionDo) withDO(do gen.Dao) *optionDo {
|
|
o.DO = *do.(*gen.DO)
|
|
return o
|
|
}
|