123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- // 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"
- "gadmin/internal/gorm/model"
- )
- func newChapter(db *gorm.DB, opts ...gen.DOOption) chapter {
- _chapter := chapter{}
- _chapter.chapterDo.UseDB(db, opts...)
- _chapter.chapterDo.UseModel(&model.Chapter{})
- tableName := _chapter.chapterDo.TableName()
- _chapter.ALL = field.NewAsterisk(tableName)
- _chapter.ID = field.NewInt64(tableName, "id")
- _chapter.PlayerID = field.NewInt64(tableName, "player_id")
- _chapter.ServerID = field.NewInt32(tableName, "server_id")
- _chapter.ChapterID = field.NewInt32(tableName, "chapter_id")
- _chapter.Degree = field.NewString(tableName, "degree")
- _chapter.ChallengeCount = field.NewInt32(tableName, "challenge_count")
- _chapter.ClearanceCount = field.NewInt32(tableName, "clearance_count")
- _chapter.FailCount = field.NewInt32(tableName, "fail_count")
- _chapter.Difficulty = field.NewInt32(tableName, "difficulty")
- _chapter.IsPass = field.NewInt32(tableName, "is_pass")
- _chapter.PassCount = field.NewInt32(tableName, "pass_count")
- _chapter.CreatedAt = field.NewTime(tableName, "created_at")
- _chapter.UpdatedAt = field.NewTime(tableName, "updated_at")
- _chapter.fillFieldMap()
- return _chapter
- }
- type chapter struct {
- chapterDo
- ALL field.Asterisk
- ID field.Int64
- PlayerID field.Int64 // 玩家ID
- ServerID field.Int32 // 服务器ID
- ChapterID field.Int32 // 章节ID
- Degree field.String // 难度系数
- ChallengeCount field.Int32 // 总挑战次数
- ClearanceCount field.Int32 // 通关次数
- FailCount field.Int32 // 失败次数
- Difficulty field.Int32 // 难度
- IsPass field.Int32 // 是否通关
- PassCount field.Int32 // 通关房间数
- CreatedAt field.Time // 创建时间
- UpdatedAt field.Time // 更新时间
- fieldMap map[string]field.Expr
- }
- func (c chapter) Table(newTableName string) *chapter {
- c.chapterDo.UseTable(newTableName)
- return c.updateTableName(newTableName)
- }
- func (c chapter) As(alias string) *chapter {
- c.chapterDo.DO = *(c.chapterDo.As(alias).(*gen.DO))
- return c.updateTableName(alias)
- }
- func (c *chapter) updateTableName(table string) *chapter {
- c.ALL = field.NewAsterisk(table)
- c.ID = field.NewInt64(table, "id")
- c.PlayerID = field.NewInt64(table, "player_id")
- c.ServerID = field.NewInt32(table, "server_id")
- c.ChapterID = field.NewInt32(table, "chapter_id")
- c.Degree = field.NewString(table, "degree")
- c.ChallengeCount = field.NewInt32(table, "challenge_count")
- c.ClearanceCount = field.NewInt32(table, "clearance_count")
- c.FailCount = field.NewInt32(table, "fail_count")
- c.Difficulty = field.NewInt32(table, "difficulty")
- c.IsPass = field.NewInt32(table, "is_pass")
- c.PassCount = field.NewInt32(table, "pass_count")
- c.CreatedAt = field.NewTime(table, "created_at")
- c.UpdatedAt = field.NewTime(table, "updated_at")
- c.fillFieldMap()
- return c
- }
- func (c *chapter) 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 *chapter) fillFieldMap() {
- c.fieldMap = make(map[string]field.Expr, 13)
- c.fieldMap["id"] = c.ID
- c.fieldMap["player_id"] = c.PlayerID
- c.fieldMap["server_id"] = c.ServerID
- c.fieldMap["chapter_id"] = c.ChapterID
- c.fieldMap["degree"] = c.Degree
- c.fieldMap["challenge_count"] = c.ChallengeCount
- c.fieldMap["clearance_count"] = c.ClearanceCount
- c.fieldMap["fail_count"] = c.FailCount
- c.fieldMap["difficulty"] = c.Difficulty
- c.fieldMap["is_pass"] = c.IsPass
- c.fieldMap["pass_count"] = c.PassCount
- c.fieldMap["created_at"] = c.CreatedAt
- c.fieldMap["updated_at"] = c.UpdatedAt
- }
- func (c chapter) clone(db *gorm.DB) chapter {
- c.chapterDo.ReplaceConnPool(db.Statement.ConnPool)
- return c
- }
- func (c chapter) replaceDB(db *gorm.DB) chapter {
- c.chapterDo.ReplaceDB(db)
- return c
- }
- type chapterDo struct{ gen.DO }
- func (c chapterDo) Debug() *chapterDo {
- return c.withDO(c.DO.Debug())
- }
- func (c chapterDo) WithContext(ctx context.Context) *chapterDo {
- return c.withDO(c.DO.WithContext(ctx))
- }
- func (c chapterDo) ReadDB() *chapterDo {
- return c.Clauses(dbresolver.Read)
- }
- func (c chapterDo) WriteDB() *chapterDo {
- return c.Clauses(dbresolver.Write)
- }
- func (c chapterDo) Session(config *gorm.Session) *chapterDo {
- return c.withDO(c.DO.Session(config))
- }
- func (c chapterDo) Clauses(conds ...clause.Expression) *chapterDo {
- return c.withDO(c.DO.Clauses(conds...))
- }
- func (c chapterDo) Returning(value interface{}, columns ...string) *chapterDo {
- return c.withDO(c.DO.Returning(value, columns...))
- }
- func (c chapterDo) Not(conds ...gen.Condition) *chapterDo {
- return c.withDO(c.DO.Not(conds...))
- }
- func (c chapterDo) Or(conds ...gen.Condition) *chapterDo {
- return c.withDO(c.DO.Or(conds...))
- }
- func (c chapterDo) Select(conds ...field.Expr) *chapterDo {
- return c.withDO(c.DO.Select(conds...))
- }
- func (c chapterDo) Where(conds ...gen.Condition) *chapterDo {
- return c.withDO(c.DO.Where(conds...))
- }
- func (c chapterDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *chapterDo {
- return c.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
- }
- func (c chapterDo) Order(conds ...field.Expr) *chapterDo {
- return c.withDO(c.DO.Order(conds...))
- }
- func (c chapterDo) Distinct(cols ...field.Expr) *chapterDo {
- return c.withDO(c.DO.Distinct(cols...))
- }
- func (c chapterDo) Omit(cols ...field.Expr) *chapterDo {
- return c.withDO(c.DO.Omit(cols...))
- }
- func (c chapterDo) Join(table schema.Tabler, on ...field.Expr) *chapterDo {
- return c.withDO(c.DO.Join(table, on...))
- }
- func (c chapterDo) LeftJoin(table schema.Tabler, on ...field.Expr) *chapterDo {
- return c.withDO(c.DO.LeftJoin(table, on...))
- }
- func (c chapterDo) RightJoin(table schema.Tabler, on ...field.Expr) *chapterDo {
- return c.withDO(c.DO.RightJoin(table, on...))
- }
- func (c chapterDo) Group(cols ...field.Expr) *chapterDo {
- return c.withDO(c.DO.Group(cols...))
- }
- func (c chapterDo) Having(conds ...gen.Condition) *chapterDo {
- return c.withDO(c.DO.Having(conds...))
- }
- func (c chapterDo) Limit(limit int) *chapterDo {
- return c.withDO(c.DO.Limit(limit))
- }
- func (c chapterDo) Offset(offset int) *chapterDo {
- return c.withDO(c.DO.Offset(offset))
- }
- func (c chapterDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *chapterDo {
- return c.withDO(c.DO.Scopes(funcs...))
- }
- func (c chapterDo) Unscoped() *chapterDo {
- return c.withDO(c.DO.Unscoped())
- }
- func (c chapterDo) Create(values ...*model.Chapter) error {
- if len(values) == 0 {
- return nil
- }
- return c.DO.Create(values)
- }
- func (c chapterDo) CreateInBatches(values []*model.Chapter, 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 chapterDo) Save(values ...*model.Chapter) error {
- if len(values) == 0 {
- return nil
- }
- return c.DO.Save(values)
- }
- func (c chapterDo) First() (*model.Chapter, error) {
- if result, err := c.DO.First(); err != nil {
- return nil, err
- } else {
- return result.(*model.Chapter), nil
- }
- }
- func (c chapterDo) Take() (*model.Chapter, error) {
- if result, err := c.DO.Take(); err != nil {
- return nil, err
- } else {
- return result.(*model.Chapter), nil
- }
- }
- func (c chapterDo) Last() (*model.Chapter, error) {
- if result, err := c.DO.Last(); err != nil {
- return nil, err
- } else {
- return result.(*model.Chapter), nil
- }
- }
- func (c chapterDo) Find() ([]*model.Chapter, error) {
- result, err := c.DO.Find()
- return result.([]*model.Chapter), err
- }
- func (c chapterDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Chapter, err error) {
- buf := make([]*model.Chapter, 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 chapterDo) FindInBatches(result *[]*model.Chapter, batchSize int, fc func(tx gen.Dao, batch int) error) error {
- return c.DO.FindInBatches(result, batchSize, fc)
- }
- func (c chapterDo) Attrs(attrs ...field.AssignExpr) *chapterDo {
- return c.withDO(c.DO.Attrs(attrs...))
- }
- func (c chapterDo) Assign(attrs ...field.AssignExpr) *chapterDo {
- return c.withDO(c.DO.Assign(attrs...))
- }
- func (c chapterDo) Joins(fields ...field.RelationField) *chapterDo {
- for _, _f := range fields {
- c = *c.withDO(c.DO.Joins(_f))
- }
- return &c
- }
- func (c chapterDo) Preload(fields ...field.RelationField) *chapterDo {
- for _, _f := range fields {
- c = *c.withDO(c.DO.Preload(_f))
- }
- return &c
- }
- func (c chapterDo) FirstOrInit() (*model.Chapter, error) {
- if result, err := c.DO.FirstOrInit(); err != nil {
- return nil, err
- } else {
- return result.(*model.Chapter), nil
- }
- }
- func (c chapterDo) FirstOrCreate() (*model.Chapter, error) {
- if result, err := c.DO.FirstOrCreate(); err != nil {
- return nil, err
- } else {
- return result.(*model.Chapter), nil
- }
- }
- func (c chapterDo) FindByPage(offset int, limit int) (result []*model.Chapter, 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 chapterDo) 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 chapterDo) Scan(result interface{}) (err error) {
- return c.DO.Scan(result)
- }
- func (c chapterDo) Delete(models ...*model.Chapter) (result gen.ResultInfo, err error) {
- return c.DO.Delete(models)
- }
- func (c *chapterDo) withDO(do gen.Dao) *chapterDo {
- c.DO = *do.(*gen.DO)
- return c
- }
|