// 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 model import ( "context" "gorm.io/gorm" "gorm.io/gorm/clause" "gorm.io/gorm/schema" "gorm.io/gen" "gorm.io/gen/field" "gorm.io/plugin/dbresolver" "icloudapp.cn/tools/service/entity" ) func newBookCategory(db *gorm.DB, opts ...gen.DOOption) MBookCategory { _MBookCategory := MBookCategory{} _MBookCategory.MBookCategoryDo.UseDB(db, opts...) _MBookCategory.MBookCategoryDo.UseModel(&entity.BookCategory{}) tableName := _MBookCategory.MBookCategoryDo.TableName() _MBookCategory.ALL = field.NewAsterisk(tableName) _MBookCategory.ID = field.NewInt64(tableName, "id") _MBookCategory.BookID = field.NewInt64(tableName, "book_id") _MBookCategory.CategoryID = field.NewInt64(tableName, "category_id") _MBookCategory.CreateAt = field.NewTime(tableName, "create_at") _MBookCategory.UpdateAt = field.NewTime(tableName, "update_at") _MBookCategory.fillFieldMap() return _MBookCategory } type MBookCategory struct { MBookCategoryDo MBookCategoryDo ALL field.Asterisk ID field.Int64 // ID BookID field.Int64 // 书籍ID CategoryID field.Int64 // 分类ID CreateAt field.Time // 创建时间 UpdateAt field.Time // 更新时间 fieldMap map[string]field.Expr } func (b MBookCategory) Table(newTableName string) *MBookCategory { b.MBookCategoryDo.UseTable(newTableName) return b.updateTableName(newTableName) } func (b MBookCategory) As(alias string) *MBookCategory { b.MBookCategoryDo.DO = *(b.MBookCategoryDo.As(alias).(*gen.DO)) return b.updateTableName(alias) } func (b *MBookCategory) updateTableName(table string) *MBookCategory { b.ALL = field.NewAsterisk(table) b.ID = field.NewInt64(table, "id") b.BookID = field.NewInt64(table, "book_id") b.CategoryID = field.NewInt64(table, "category_id") b.CreateAt = field.NewTime(table, "create_at") b.UpdateAt = field.NewTime(table, "update_at") b.fillFieldMap() return b } func (b *MBookCategory) WithContext(ctx context.Context) IBookCategoryDo { return b.MBookCategoryDo.WithContext(ctx) } func (b MBookCategory) TableName() string { return b.MBookCategoryDo.TableName() } func (b MBookCategory) Alias() string { return b.MBookCategoryDo.Alias() } func (b *MBookCategory) GetFieldByName(fieldName string) (field.OrderExpr, bool) { _f, ok := b.fieldMap[fieldName] if !ok || _f == nil { return nil, false } _oe, ok := _f.(field.OrderExpr) return _oe, ok } func (b *MBookCategory) fillFieldMap() { b.fieldMap = make(map[string]field.Expr, 5) b.fieldMap["id"] = b.ID b.fieldMap["book_id"] = b.BookID b.fieldMap["category_id"] = b.CategoryID b.fieldMap["create_at"] = b.CreateAt b.fieldMap["update_at"] = b.UpdateAt } func (b MBookCategory) clone(db *gorm.DB) MBookCategory { b.MBookCategoryDo.ReplaceConnPool(db.Statement.ConnPool) return b } func (b MBookCategory) replaceDB(db *gorm.DB) MBookCategory { b.MBookCategoryDo.ReplaceDB(db) return b } type MBookCategoryDo struct{ gen.DO } type IBookCategoryDo interface { gen.SubQuery Debug() IBookCategoryDo WithContext(ctx context.Context) IBookCategoryDo WithResult(fc func(tx gen.Dao)) gen.ResultInfo ReplaceDB(db *gorm.DB) ReadDB() IBookCategoryDo WriteDB() IBookCategoryDo As(alias string) gen.Dao Session(config *gorm.Session) IBookCategoryDo Columns(cols ...field.Expr) gen.Columns Clauses(conds ...clause.Expression) IBookCategoryDo Not(conds ...gen.Condition) IBookCategoryDo Or(conds ...gen.Condition) IBookCategoryDo Select(conds ...field.Expr) IBookCategoryDo Where(conds ...gen.Condition) IBookCategoryDo Order(conds ...field.Expr) IBookCategoryDo Distinct(cols ...field.Expr) IBookCategoryDo Omit(cols ...field.Expr) IBookCategoryDo Join(table schema.Tabler, on ...field.Expr) IBookCategoryDo LeftJoin(table schema.Tabler, on ...field.Expr) IBookCategoryDo RightJoin(table schema.Tabler, on ...field.Expr) IBookCategoryDo Group(cols ...field.Expr) IBookCategoryDo Having(conds ...gen.Condition) IBookCategoryDo Limit(limit int) IBookCategoryDo Offset(offset int) IBookCategoryDo Count() (count int64, err error) Scopes(funcs ...func(gen.Dao) gen.Dao) IBookCategoryDo Unscoped() IBookCategoryDo Create(values ...*entity.BookCategory) error CreateInBatches(values []*entity.BookCategory, batchSize int) error Save(values ...*entity.BookCategory) error First() (*entity.BookCategory, error) Take() (*entity.BookCategory, error) Last() (*entity.BookCategory, error) Find() ([]*entity.BookCategory, error) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.BookCategory, err error) FindInBatches(result *[]*entity.BookCategory, batchSize int, fc func(tx gen.Dao, batch int) error) error Pluck(column field.Expr, dest interface{}) error Delete(...*entity.BookCategory) (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) IBookCategoryDo Assign(attrs ...field.AssignExpr) IBookCategoryDo Joins(fields ...field.RelationField) IBookCategoryDo Preload(fields ...field.RelationField) IBookCategoryDo FirstOrInit() (*entity.BookCategory, error) FirstOrCreate() (*entity.BookCategory, error) FindByPage(offset int, limit int) (result []*entity.BookCategory, 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) IBookCategoryDo UnderlyingDB() *gorm.DB schema.Tabler } func (b MBookCategoryDo) Debug() IBookCategoryDo { return b.withDO(b.DO.Debug()) } func (b MBookCategoryDo) WithContext(ctx context.Context) IBookCategoryDo { return b.withDO(b.DO.WithContext(ctx)) } func (b MBookCategoryDo) ReadDB() IBookCategoryDo { return b.Clauses(dbresolver.Read) } func (b MBookCategoryDo) WriteDB() IBookCategoryDo { return b.Clauses(dbresolver.Write) } func (b MBookCategoryDo) Session(config *gorm.Session) IBookCategoryDo { return b.withDO(b.DO.Session(config)) } func (b MBookCategoryDo) Clauses(conds ...clause.Expression) IBookCategoryDo { return b.withDO(b.DO.Clauses(conds...)) } func (b MBookCategoryDo) Returning(value interface{}, columns ...string) IBookCategoryDo { return b.withDO(b.DO.Returning(value, columns...)) } func (b MBookCategoryDo) Not(conds ...gen.Condition) IBookCategoryDo { return b.withDO(b.DO.Not(conds...)) } func (b MBookCategoryDo) Or(conds ...gen.Condition) IBookCategoryDo { return b.withDO(b.DO.Or(conds...)) } func (b MBookCategoryDo) Select(conds ...field.Expr) IBookCategoryDo { return b.withDO(b.DO.Select(conds...)) } func (b MBookCategoryDo) Where(conds ...gen.Condition) IBookCategoryDo { return b.withDO(b.DO.Where(conds...)) } func (b MBookCategoryDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) IBookCategoryDo { return b.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB())) } func (b MBookCategoryDo) Order(conds ...field.Expr) IBookCategoryDo { return b.withDO(b.DO.Order(conds...)) } func (b MBookCategoryDo) Distinct(cols ...field.Expr) IBookCategoryDo { return b.withDO(b.DO.Distinct(cols...)) } func (b MBookCategoryDo) Omit(cols ...field.Expr) IBookCategoryDo { return b.withDO(b.DO.Omit(cols...)) } func (b MBookCategoryDo) Join(table schema.Tabler, on ...field.Expr) IBookCategoryDo { return b.withDO(b.DO.Join(table, on...)) } func (b MBookCategoryDo) LeftJoin(table schema.Tabler, on ...field.Expr) IBookCategoryDo { return b.withDO(b.DO.LeftJoin(table, on...)) } func (b MBookCategoryDo) RightJoin(table schema.Tabler, on ...field.Expr) IBookCategoryDo { return b.withDO(b.DO.RightJoin(table, on...)) } func (b MBookCategoryDo) Group(cols ...field.Expr) IBookCategoryDo { return b.withDO(b.DO.Group(cols...)) } func (b MBookCategoryDo) Having(conds ...gen.Condition) IBookCategoryDo { return b.withDO(b.DO.Having(conds...)) } func (b MBookCategoryDo) Limit(limit int) IBookCategoryDo { return b.withDO(b.DO.Limit(limit)) } func (b MBookCategoryDo) Offset(offset int) IBookCategoryDo { return b.withDO(b.DO.Offset(offset)) } func (b MBookCategoryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IBookCategoryDo { return b.withDO(b.DO.Scopes(funcs...)) } func (b MBookCategoryDo) Unscoped() IBookCategoryDo { return b.withDO(b.DO.Unscoped()) } func (b MBookCategoryDo) Create(values ...*entity.BookCategory) error { if len(values) == 0 { return nil } return b.DO.Create(values) } func (b MBookCategoryDo) CreateInBatches(values []*entity.BookCategory, batchSize int) error { return b.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 (b MBookCategoryDo) Save(values ...*entity.BookCategory) error { if len(values) == 0 { return nil } return b.DO.Save(values) } func (b MBookCategoryDo) First() (*entity.BookCategory, error) { if result, err := b.DO.First(); err != nil { return nil, err } else { return result.(*entity.BookCategory), nil } } func (b MBookCategoryDo) Take() (*entity.BookCategory, error) { if result, err := b.DO.Take(); err != nil { return nil, err } else { return result.(*entity.BookCategory), nil } } func (b MBookCategoryDo) Last() (*entity.BookCategory, error) { if result, err := b.DO.Last(); err != nil { return nil, err } else { return result.(*entity.BookCategory), nil } } func (b MBookCategoryDo) Find() ([]*entity.BookCategory, error) { result, err := b.DO.Find() return result.([]*entity.BookCategory), err } func (b MBookCategoryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.BookCategory, err error) { buf := make([]*entity.BookCategory, 0, batchSize) err = b.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 (b MBookCategoryDo) FindInBatches(result *[]*entity.BookCategory, batchSize int, fc func(tx gen.Dao, batch int) error) error { return b.DO.FindInBatches(result, batchSize, fc) } func (b MBookCategoryDo) Attrs(attrs ...field.AssignExpr) IBookCategoryDo { return b.withDO(b.DO.Attrs(attrs...)) } func (b MBookCategoryDo) Assign(attrs ...field.AssignExpr) IBookCategoryDo { return b.withDO(b.DO.Assign(attrs...)) } func (b MBookCategoryDo) Joins(fields ...field.RelationField) IBookCategoryDo { for _, _f := range fields { b = *b.withDO(b.DO.Joins(_f)) } return &b } func (b MBookCategoryDo) Preload(fields ...field.RelationField) IBookCategoryDo { for _, _f := range fields { b = *b.withDO(b.DO.Preload(_f)) } return &b } func (b MBookCategoryDo) FirstOrInit() (*entity.BookCategory, error) { if result, err := b.DO.FirstOrInit(); err != nil { return nil, err } else { return result.(*entity.BookCategory), nil } } func (b MBookCategoryDo) FirstOrCreate() (*entity.BookCategory, error) { if result, err := b.DO.FirstOrCreate(); err != nil { return nil, err } else { return result.(*entity.BookCategory), nil } } func (b MBookCategoryDo) FindByPage(offset int, limit int) (result []*entity.BookCategory, count int64, err error) { result, err = b.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 = b.Offset(-1).Limit(-1).Count() return } func (b MBookCategoryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { count, err = b.Count() if err != nil { return } err = b.Offset(offset).Limit(limit).Scan(result) return } func (b MBookCategoryDo) Scan(result interface{}) (err error) { return b.DO.Scan(result) } func (b MBookCategoryDo) Delete(models ...*entity.BookCategory) (result gen.ResultInfo, err error) { return b.DO.Delete(models) } func (b *MBookCategoryDo) withDO(do gen.Dao) *MBookCategoryDo { b.DO = *do.(*gen.DO) return b }