category.gen.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. "wechat-api/database/dao/wechat/model"
  14. )
  15. func newCategory(db *gorm.DB, opts ...gen.DOOption) category {
  16. _category := category{}
  17. _category.categoryDo.UseDB(db, opts...)
  18. _category.categoryDo.UseModel(&model.Category{})
  19. tableName := _category.categoryDo.TableName()
  20. _category.ALL = field.NewAsterisk(tableName)
  21. _category.ID = field.NewInt64(tableName, "id")
  22. _category.CreatedAt = field.NewTime(tableName, "created_at")
  23. _category.UpdatedAt = field.NewTime(tableName, "updated_at")
  24. _category.DeletedAt = field.NewField(tableName, "deleted_at")
  25. _category.Name = field.NewString(tableName, "name")
  26. _category.OrganizationID = field.NewInt64(tableName, "organization_id")
  27. _category.fillFieldMap()
  28. return _category
  29. }
  30. type category struct {
  31. categoryDo
  32. ALL field.Asterisk
  33. ID field.Int64
  34. CreatedAt field.Time // Create Time | 创建日期
  35. UpdatedAt field.Time // Update Time | 修改日期
  36. DeletedAt field.Field // Delete Time | 删除日期
  37. Name field.String // name | agent 名称
  38. OrganizationID field.Int64 // organization_id | 租户id
  39. fieldMap map[string]field.Expr
  40. }
  41. func (c category) Table(newTableName string) *category {
  42. c.categoryDo.UseTable(newTableName)
  43. return c.updateTableName(newTableName)
  44. }
  45. func (c category) As(alias string) *category {
  46. c.categoryDo.DO = *(c.categoryDo.As(alias).(*gen.DO))
  47. return c.updateTableName(alias)
  48. }
  49. func (c *category) updateTableName(table string) *category {
  50. c.ALL = field.NewAsterisk(table)
  51. c.ID = field.NewInt64(table, "id")
  52. c.CreatedAt = field.NewTime(table, "created_at")
  53. c.UpdatedAt = field.NewTime(table, "updated_at")
  54. c.DeletedAt = field.NewField(table, "deleted_at")
  55. c.Name = field.NewString(table, "name")
  56. c.OrganizationID = field.NewInt64(table, "organization_id")
  57. c.fillFieldMap()
  58. return c
  59. }
  60. func (c *category) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
  61. _f, ok := c.fieldMap[fieldName]
  62. if !ok || _f == nil {
  63. return nil, false
  64. }
  65. _oe, ok := _f.(field.OrderExpr)
  66. return _oe, ok
  67. }
  68. func (c *category) fillFieldMap() {
  69. c.fieldMap = make(map[string]field.Expr, 6)
  70. c.fieldMap["id"] = c.ID
  71. c.fieldMap["created_at"] = c.CreatedAt
  72. c.fieldMap["updated_at"] = c.UpdatedAt
  73. c.fieldMap["deleted_at"] = c.DeletedAt
  74. c.fieldMap["name"] = c.Name
  75. c.fieldMap["organization_id"] = c.OrganizationID
  76. }
  77. func (c category) clone(db *gorm.DB) category {
  78. c.categoryDo.ReplaceConnPool(db.Statement.ConnPool)
  79. return c
  80. }
  81. func (c category) replaceDB(db *gorm.DB) category {
  82. c.categoryDo.ReplaceDB(db)
  83. return c
  84. }
  85. type categoryDo struct{ gen.DO }
  86. type ICategoryDo interface {
  87. gen.SubQuery
  88. Debug() ICategoryDo
  89. WithContext(ctx context.Context) ICategoryDo
  90. WithResult(fc func(tx gen.Dao)) gen.ResultInfo
  91. ReplaceDB(db *gorm.DB)
  92. ReadDB() ICategoryDo
  93. WriteDB() ICategoryDo
  94. As(alias string) gen.Dao
  95. Session(config *gorm.Session) ICategoryDo
  96. Columns(cols ...field.Expr) gen.Columns
  97. Clauses(conds ...clause.Expression) ICategoryDo
  98. Not(conds ...gen.Condition) ICategoryDo
  99. Or(conds ...gen.Condition) ICategoryDo
  100. Select(conds ...field.Expr) ICategoryDo
  101. Where(conds ...gen.Condition) ICategoryDo
  102. Order(conds ...field.Expr) ICategoryDo
  103. Distinct(cols ...field.Expr) ICategoryDo
  104. Omit(cols ...field.Expr) ICategoryDo
  105. Join(table schema.Tabler, on ...field.Expr) ICategoryDo
  106. LeftJoin(table schema.Tabler, on ...field.Expr) ICategoryDo
  107. RightJoin(table schema.Tabler, on ...field.Expr) ICategoryDo
  108. Group(cols ...field.Expr) ICategoryDo
  109. Having(conds ...gen.Condition) ICategoryDo
  110. Limit(limit int) ICategoryDo
  111. Offset(offset int) ICategoryDo
  112. Count() (count int64, err error)
  113. Scopes(funcs ...func(gen.Dao) gen.Dao) ICategoryDo
  114. Unscoped() ICategoryDo
  115. Create(values ...*model.Category) error
  116. CreateInBatches(values []*model.Category, batchSize int) error
  117. Save(values ...*model.Category) error
  118. First() (*model.Category, error)
  119. Take() (*model.Category, error)
  120. Last() (*model.Category, error)
  121. Find() ([]*model.Category, error)
  122. FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Category, err error)
  123. FindInBatches(result *[]*model.Category, batchSize int, fc func(tx gen.Dao, batch int) error) error
  124. Pluck(column field.Expr, dest interface{}) error
  125. Delete(...*model.Category) (info gen.ResultInfo, err error)
  126. Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
  127. UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
  128. Updates(value interface{}) (info gen.ResultInfo, err error)
  129. UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
  130. UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
  131. UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
  132. UpdateFrom(q gen.SubQuery) gen.Dao
  133. Attrs(attrs ...field.AssignExpr) ICategoryDo
  134. Assign(attrs ...field.AssignExpr) ICategoryDo
  135. Joins(fields ...field.RelationField) ICategoryDo
  136. Preload(fields ...field.RelationField) ICategoryDo
  137. FirstOrInit() (*model.Category, error)
  138. FirstOrCreate() (*model.Category, error)
  139. FindByPage(offset int, limit int) (result []*model.Category, count int64, err error)
  140. ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
  141. Scan(result interface{}) (err error)
  142. Returning(value interface{}, columns ...string) ICategoryDo
  143. UnderlyingDB() *gorm.DB
  144. schema.Tabler
  145. }
  146. func (c categoryDo) Debug() ICategoryDo {
  147. return c.withDO(c.DO.Debug())
  148. }
  149. func (c categoryDo) WithContext(ctx context.Context) ICategoryDo {
  150. return c.withDO(c.DO.WithContext(ctx))
  151. }
  152. func (c categoryDo) ReadDB() ICategoryDo {
  153. return c.Clauses(dbresolver.Read)
  154. }
  155. func (c categoryDo) WriteDB() ICategoryDo {
  156. return c.Clauses(dbresolver.Write)
  157. }
  158. func (c categoryDo) Session(config *gorm.Session) ICategoryDo {
  159. return c.withDO(c.DO.Session(config))
  160. }
  161. func (c categoryDo) Clauses(conds ...clause.Expression) ICategoryDo {
  162. return c.withDO(c.DO.Clauses(conds...))
  163. }
  164. func (c categoryDo) Returning(value interface{}, columns ...string) ICategoryDo {
  165. return c.withDO(c.DO.Returning(value, columns...))
  166. }
  167. func (c categoryDo) Not(conds ...gen.Condition) ICategoryDo {
  168. return c.withDO(c.DO.Not(conds...))
  169. }
  170. func (c categoryDo) Or(conds ...gen.Condition) ICategoryDo {
  171. return c.withDO(c.DO.Or(conds...))
  172. }
  173. func (c categoryDo) Select(conds ...field.Expr) ICategoryDo {
  174. return c.withDO(c.DO.Select(conds...))
  175. }
  176. func (c categoryDo) Where(conds ...gen.Condition) ICategoryDo {
  177. return c.withDO(c.DO.Where(conds...))
  178. }
  179. func (c categoryDo) Order(conds ...field.Expr) ICategoryDo {
  180. return c.withDO(c.DO.Order(conds...))
  181. }
  182. func (c categoryDo) Distinct(cols ...field.Expr) ICategoryDo {
  183. return c.withDO(c.DO.Distinct(cols...))
  184. }
  185. func (c categoryDo) Omit(cols ...field.Expr) ICategoryDo {
  186. return c.withDO(c.DO.Omit(cols...))
  187. }
  188. func (c categoryDo) Join(table schema.Tabler, on ...field.Expr) ICategoryDo {
  189. return c.withDO(c.DO.Join(table, on...))
  190. }
  191. func (c categoryDo) LeftJoin(table schema.Tabler, on ...field.Expr) ICategoryDo {
  192. return c.withDO(c.DO.LeftJoin(table, on...))
  193. }
  194. func (c categoryDo) RightJoin(table schema.Tabler, on ...field.Expr) ICategoryDo {
  195. return c.withDO(c.DO.RightJoin(table, on...))
  196. }
  197. func (c categoryDo) Group(cols ...field.Expr) ICategoryDo {
  198. return c.withDO(c.DO.Group(cols...))
  199. }
  200. func (c categoryDo) Having(conds ...gen.Condition) ICategoryDo {
  201. return c.withDO(c.DO.Having(conds...))
  202. }
  203. func (c categoryDo) Limit(limit int) ICategoryDo {
  204. return c.withDO(c.DO.Limit(limit))
  205. }
  206. func (c categoryDo) Offset(offset int) ICategoryDo {
  207. return c.withDO(c.DO.Offset(offset))
  208. }
  209. func (c categoryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ICategoryDo {
  210. return c.withDO(c.DO.Scopes(funcs...))
  211. }
  212. func (c categoryDo) Unscoped() ICategoryDo {
  213. return c.withDO(c.DO.Unscoped())
  214. }
  215. func (c categoryDo) Create(values ...*model.Category) error {
  216. if len(values) == 0 {
  217. return nil
  218. }
  219. return c.DO.Create(values)
  220. }
  221. func (c categoryDo) CreateInBatches(values []*model.Category, batchSize int) error {
  222. return c.DO.CreateInBatches(values, batchSize)
  223. }
  224. // Save : !!! underlying implementation is different with GORM
  225. // The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
  226. func (c categoryDo) Save(values ...*model.Category) error {
  227. if len(values) == 0 {
  228. return nil
  229. }
  230. return c.DO.Save(values)
  231. }
  232. func (c categoryDo) First() (*model.Category, error) {
  233. if result, err := c.DO.First(); err != nil {
  234. return nil, err
  235. } else {
  236. return result.(*model.Category), nil
  237. }
  238. }
  239. func (c categoryDo) Take() (*model.Category, error) {
  240. if result, err := c.DO.Take(); err != nil {
  241. return nil, err
  242. } else {
  243. return result.(*model.Category), nil
  244. }
  245. }
  246. func (c categoryDo) Last() (*model.Category, error) {
  247. if result, err := c.DO.Last(); err != nil {
  248. return nil, err
  249. } else {
  250. return result.(*model.Category), nil
  251. }
  252. }
  253. func (c categoryDo) Find() ([]*model.Category, error) {
  254. result, err := c.DO.Find()
  255. return result.([]*model.Category), err
  256. }
  257. func (c categoryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Category, err error) {
  258. buf := make([]*model.Category, 0, batchSize)
  259. err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
  260. defer func() { results = append(results, buf...) }()
  261. return fc(tx, batch)
  262. })
  263. return results, err
  264. }
  265. func (c categoryDo) FindInBatches(result *[]*model.Category, batchSize int, fc func(tx gen.Dao, batch int) error) error {
  266. return c.DO.FindInBatches(result, batchSize, fc)
  267. }
  268. func (c categoryDo) Attrs(attrs ...field.AssignExpr) ICategoryDo {
  269. return c.withDO(c.DO.Attrs(attrs...))
  270. }
  271. func (c categoryDo) Assign(attrs ...field.AssignExpr) ICategoryDo {
  272. return c.withDO(c.DO.Assign(attrs...))
  273. }
  274. func (c categoryDo) Joins(fields ...field.RelationField) ICategoryDo {
  275. for _, _f := range fields {
  276. c = *c.withDO(c.DO.Joins(_f))
  277. }
  278. return &c
  279. }
  280. func (c categoryDo) Preload(fields ...field.RelationField) ICategoryDo {
  281. for _, _f := range fields {
  282. c = *c.withDO(c.DO.Preload(_f))
  283. }
  284. return &c
  285. }
  286. func (c categoryDo) FirstOrInit() (*model.Category, error) {
  287. if result, err := c.DO.FirstOrInit(); err != nil {
  288. return nil, err
  289. } else {
  290. return result.(*model.Category), nil
  291. }
  292. }
  293. func (c categoryDo) FirstOrCreate() (*model.Category, error) {
  294. if result, err := c.DO.FirstOrCreate(); err != nil {
  295. return nil, err
  296. } else {
  297. return result.(*model.Category), nil
  298. }
  299. }
  300. func (c categoryDo) FindByPage(offset int, limit int) (result []*model.Category, count int64, err error) {
  301. result, err = c.Offset(offset).Limit(limit).Find()
  302. if err != nil {
  303. return
  304. }
  305. if size := len(result); 0 < limit && 0 < size && size < limit {
  306. count = int64(size + offset)
  307. return
  308. }
  309. count, err = c.Offset(-1).Limit(-1).Count()
  310. return
  311. }
  312. func (c categoryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
  313. count, err = c.Count()
  314. if err != nil {
  315. return
  316. }
  317. err = c.Offset(offset).Limit(limit).Scan(result)
  318. return
  319. }
  320. func (c categoryDo) Scan(result interface{}) (err error) {
  321. return c.DO.Scan(result)
  322. }
  323. func (c categoryDo) Delete(models ...*model.Category) (result gen.ResultInfo, err error) {
  324. return c.DO.Delete(models)
  325. }
  326. func (c *categoryDo) withDO(do gen.Dao) *categoryDo {
  327. c.DO = *do.(*gen.DO)
  328. return c
  329. }