chapter.gen.go 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. // Code generated by gorm.io/gen. DO NOT EDIT.
  2. // Code generated by gorm.io/gen. DO NOT EDIT.
  3. // Code generated by gorm.io/gen. DO NOT EDIT.
  4. package query
  5. import (
  6. "context"
  7. "gorm.io/gorm"
  8. "gorm.io/gorm/clause"
  9. "gorm.io/gorm/schema"
  10. "gorm.io/gen"
  11. "gorm.io/gen/field"
  12. "gorm.io/plugin/dbresolver"
  13. "gadmin/internal/gorm/model"
  14. )
  15. func newChapter(db *gorm.DB, opts ...gen.DOOption) chapter {
  16. _chapter := chapter{}
  17. _chapter.chapterDo.UseDB(db, opts...)
  18. _chapter.chapterDo.UseModel(&model.Chapter{})
  19. tableName := _chapter.chapterDo.TableName()
  20. _chapter.ALL = field.NewAsterisk(tableName)
  21. _chapter.ID = field.NewInt64(tableName, "id")
  22. _chapter.PlayerID = field.NewInt64(tableName, "player_id")
  23. _chapter.ServerID = field.NewInt32(tableName, "server_id")
  24. _chapter.ChapterID = field.NewInt32(tableName, "chapter_id")
  25. _chapter.Degree = field.NewString(tableName, "degree")
  26. _chapter.ChallengeCount = field.NewInt32(tableName, "challenge_count")
  27. _chapter.ClearanceCount = field.NewInt32(tableName, "clearance_count")
  28. _chapter.FailCount = field.NewInt32(tableName, "fail_count")
  29. _chapter.Difficulty = field.NewInt32(tableName, "difficulty")
  30. _chapter.IsPass = field.NewInt32(tableName, "is_pass")
  31. _chapter.PassCount = field.NewInt32(tableName, "pass_count")
  32. _chapter.CreatedAt = field.NewTime(tableName, "created_at")
  33. _chapter.UpdatedAt = field.NewTime(tableName, "updated_at")
  34. _chapter.fillFieldMap()
  35. return _chapter
  36. }
  37. type chapter struct {
  38. chapterDo
  39. ALL field.Asterisk
  40. ID field.Int64
  41. PlayerID field.Int64 // 玩家ID
  42. ServerID field.Int32 // 服务器ID
  43. ChapterID field.Int32 // 章节ID
  44. Degree field.String // 难度系数
  45. ChallengeCount field.Int32 // 总挑战次数
  46. ClearanceCount field.Int32 // 通关次数
  47. FailCount field.Int32 // 失败次数
  48. Difficulty field.Int32 // 难度
  49. IsPass field.Int32 // 是否通关
  50. PassCount field.Int32 // 通关房间数
  51. CreatedAt field.Time // 创建时间
  52. UpdatedAt field.Time // 更新时间
  53. fieldMap map[string]field.Expr
  54. }
  55. func (c chapter) Table(newTableName string) *chapter {
  56. c.chapterDo.UseTable(newTableName)
  57. return c.updateTableName(newTableName)
  58. }
  59. func (c chapter) As(alias string) *chapter {
  60. c.chapterDo.DO = *(c.chapterDo.As(alias).(*gen.DO))
  61. return c.updateTableName(alias)
  62. }
  63. func (c *chapter) updateTableName(table string) *chapter {
  64. c.ALL = field.NewAsterisk(table)
  65. c.ID = field.NewInt64(table, "id")
  66. c.PlayerID = field.NewInt64(table, "player_id")
  67. c.ServerID = field.NewInt32(table, "server_id")
  68. c.ChapterID = field.NewInt32(table, "chapter_id")
  69. c.Degree = field.NewString(table, "degree")
  70. c.ChallengeCount = field.NewInt32(table, "challenge_count")
  71. c.ClearanceCount = field.NewInt32(table, "clearance_count")
  72. c.FailCount = field.NewInt32(table, "fail_count")
  73. c.Difficulty = field.NewInt32(table, "difficulty")
  74. c.IsPass = field.NewInt32(table, "is_pass")
  75. c.PassCount = field.NewInt32(table, "pass_count")
  76. c.CreatedAt = field.NewTime(table, "created_at")
  77. c.UpdatedAt = field.NewTime(table, "updated_at")
  78. c.fillFieldMap()
  79. return c
  80. }
  81. func (c *chapter) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
  82. _f, ok := c.fieldMap[fieldName]
  83. if !ok || _f == nil {
  84. return nil, false
  85. }
  86. _oe, ok := _f.(field.OrderExpr)
  87. return _oe, ok
  88. }
  89. func (c *chapter) fillFieldMap() {
  90. c.fieldMap = make(map[string]field.Expr, 13)
  91. c.fieldMap["id"] = c.ID
  92. c.fieldMap["player_id"] = c.PlayerID
  93. c.fieldMap["server_id"] = c.ServerID
  94. c.fieldMap["chapter_id"] = c.ChapterID
  95. c.fieldMap["degree"] = c.Degree
  96. c.fieldMap["challenge_count"] = c.ChallengeCount
  97. c.fieldMap["clearance_count"] = c.ClearanceCount
  98. c.fieldMap["fail_count"] = c.FailCount
  99. c.fieldMap["difficulty"] = c.Difficulty
  100. c.fieldMap["is_pass"] = c.IsPass
  101. c.fieldMap["pass_count"] = c.PassCount
  102. c.fieldMap["created_at"] = c.CreatedAt
  103. c.fieldMap["updated_at"] = c.UpdatedAt
  104. }
  105. func (c chapter) clone(db *gorm.DB) chapter {
  106. c.chapterDo.ReplaceConnPool(db.Statement.ConnPool)
  107. return c
  108. }
  109. func (c chapter) replaceDB(db *gorm.DB) chapter {
  110. c.chapterDo.ReplaceDB(db)
  111. return c
  112. }
  113. type chapterDo struct{ gen.DO }
  114. func (c chapterDo) Debug() *chapterDo {
  115. return c.withDO(c.DO.Debug())
  116. }
  117. func (c chapterDo) WithContext(ctx context.Context) *chapterDo {
  118. return c.withDO(c.DO.WithContext(ctx))
  119. }
  120. func (c chapterDo) ReadDB() *chapterDo {
  121. return c.Clauses(dbresolver.Read)
  122. }
  123. func (c chapterDo) WriteDB() *chapterDo {
  124. return c.Clauses(dbresolver.Write)
  125. }
  126. func (c chapterDo) Session(config *gorm.Session) *chapterDo {
  127. return c.withDO(c.DO.Session(config))
  128. }
  129. func (c chapterDo) Clauses(conds ...clause.Expression) *chapterDo {
  130. return c.withDO(c.DO.Clauses(conds...))
  131. }
  132. func (c chapterDo) Returning(value interface{}, columns ...string) *chapterDo {
  133. return c.withDO(c.DO.Returning(value, columns...))
  134. }
  135. func (c chapterDo) Not(conds ...gen.Condition) *chapterDo {
  136. return c.withDO(c.DO.Not(conds...))
  137. }
  138. func (c chapterDo) Or(conds ...gen.Condition) *chapterDo {
  139. return c.withDO(c.DO.Or(conds...))
  140. }
  141. func (c chapterDo) Select(conds ...field.Expr) *chapterDo {
  142. return c.withDO(c.DO.Select(conds...))
  143. }
  144. func (c chapterDo) Where(conds ...gen.Condition) *chapterDo {
  145. return c.withDO(c.DO.Where(conds...))
  146. }
  147. func (c chapterDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *chapterDo {
  148. return c.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
  149. }
  150. func (c chapterDo) Order(conds ...field.Expr) *chapterDo {
  151. return c.withDO(c.DO.Order(conds...))
  152. }
  153. func (c chapterDo) Distinct(cols ...field.Expr) *chapterDo {
  154. return c.withDO(c.DO.Distinct(cols...))
  155. }
  156. func (c chapterDo) Omit(cols ...field.Expr) *chapterDo {
  157. return c.withDO(c.DO.Omit(cols...))
  158. }
  159. func (c chapterDo) Join(table schema.Tabler, on ...field.Expr) *chapterDo {
  160. return c.withDO(c.DO.Join(table, on...))
  161. }
  162. func (c chapterDo) LeftJoin(table schema.Tabler, on ...field.Expr) *chapterDo {
  163. return c.withDO(c.DO.LeftJoin(table, on...))
  164. }
  165. func (c chapterDo) RightJoin(table schema.Tabler, on ...field.Expr) *chapterDo {
  166. return c.withDO(c.DO.RightJoin(table, on...))
  167. }
  168. func (c chapterDo) Group(cols ...field.Expr) *chapterDo {
  169. return c.withDO(c.DO.Group(cols...))
  170. }
  171. func (c chapterDo) Having(conds ...gen.Condition) *chapterDo {
  172. return c.withDO(c.DO.Having(conds...))
  173. }
  174. func (c chapterDo) Limit(limit int) *chapterDo {
  175. return c.withDO(c.DO.Limit(limit))
  176. }
  177. func (c chapterDo) Offset(offset int) *chapterDo {
  178. return c.withDO(c.DO.Offset(offset))
  179. }
  180. func (c chapterDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *chapterDo {
  181. return c.withDO(c.DO.Scopes(funcs...))
  182. }
  183. func (c chapterDo) Unscoped() *chapterDo {
  184. return c.withDO(c.DO.Unscoped())
  185. }
  186. func (c chapterDo) Create(values ...*model.Chapter) error {
  187. if len(values) == 0 {
  188. return nil
  189. }
  190. return c.DO.Create(values)
  191. }
  192. func (c chapterDo) CreateInBatches(values []*model.Chapter, batchSize int) error {
  193. return c.DO.CreateInBatches(values, batchSize)
  194. }
  195. // Save : !!! underlying implementation is different with GORM
  196. // The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
  197. func (c chapterDo) Save(values ...*model.Chapter) error {
  198. if len(values) == 0 {
  199. return nil
  200. }
  201. return c.DO.Save(values)
  202. }
  203. func (c chapterDo) First() (*model.Chapter, error) {
  204. if result, err := c.DO.First(); err != nil {
  205. return nil, err
  206. } else {
  207. return result.(*model.Chapter), nil
  208. }
  209. }
  210. func (c chapterDo) Take() (*model.Chapter, error) {
  211. if result, err := c.DO.Take(); err != nil {
  212. return nil, err
  213. } else {
  214. return result.(*model.Chapter), nil
  215. }
  216. }
  217. func (c chapterDo) Last() (*model.Chapter, error) {
  218. if result, err := c.DO.Last(); err != nil {
  219. return nil, err
  220. } else {
  221. return result.(*model.Chapter), nil
  222. }
  223. }
  224. func (c chapterDo) Find() ([]*model.Chapter, error) {
  225. result, err := c.DO.Find()
  226. return result.([]*model.Chapter), err
  227. }
  228. func (c chapterDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Chapter, err error) {
  229. buf := make([]*model.Chapter, 0, batchSize)
  230. err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
  231. defer func() { results = append(results, buf...) }()
  232. return fc(tx, batch)
  233. })
  234. return results, err
  235. }
  236. func (c chapterDo) FindInBatches(result *[]*model.Chapter, batchSize int, fc func(tx gen.Dao, batch int) error) error {
  237. return c.DO.FindInBatches(result, batchSize, fc)
  238. }
  239. func (c chapterDo) Attrs(attrs ...field.AssignExpr) *chapterDo {
  240. return c.withDO(c.DO.Attrs(attrs...))
  241. }
  242. func (c chapterDo) Assign(attrs ...field.AssignExpr) *chapterDo {
  243. return c.withDO(c.DO.Assign(attrs...))
  244. }
  245. func (c chapterDo) Joins(fields ...field.RelationField) *chapterDo {
  246. for _, _f := range fields {
  247. c = *c.withDO(c.DO.Joins(_f))
  248. }
  249. return &c
  250. }
  251. func (c chapterDo) Preload(fields ...field.RelationField) *chapterDo {
  252. for _, _f := range fields {
  253. c = *c.withDO(c.DO.Preload(_f))
  254. }
  255. return &c
  256. }
  257. func (c chapterDo) FirstOrInit() (*model.Chapter, error) {
  258. if result, err := c.DO.FirstOrInit(); err != nil {
  259. return nil, err
  260. } else {
  261. return result.(*model.Chapter), nil
  262. }
  263. }
  264. func (c chapterDo) FirstOrCreate() (*model.Chapter, error) {
  265. if result, err := c.DO.FirstOrCreate(); err != nil {
  266. return nil, err
  267. } else {
  268. return result.(*model.Chapter), nil
  269. }
  270. }
  271. func (c chapterDo) FindByPage(offset int, limit int) (result []*model.Chapter, count int64, err error) {
  272. result, err = c.Offset(offset).Limit(limit).Find()
  273. if err != nil {
  274. return
  275. }
  276. if size := len(result); 0 < limit && 0 < size && size < limit {
  277. count = int64(size + offset)
  278. return
  279. }
  280. count, err = c.Offset(-1).Limit(-1).Count()
  281. return
  282. }
  283. func (c chapterDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
  284. count, err = c.Count()
  285. if err != nil {
  286. return
  287. }
  288. err = c.Offset(offset).Limit(limit).Scan(result)
  289. return
  290. }
  291. func (c chapterDo) Scan(result interface{}) (err error) {
  292. return c.DO.Scan(result)
  293. }
  294. func (c chapterDo) Delete(models ...*model.Chapter) (result gen.ResultInfo, err error) {
  295. return c.DO.Delete(models)
  296. }
  297. func (c *chapterDo) withDO(do gen.Dao) *chapterDo {
  298. c.DO = *do.(*gen.DO)
  299. return c
  300. }