chapter_sync.gen.go 9.3 KB

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