cache.gen.go 8.0 KB

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