config.gen.go 9.6 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 newConfig(db *gorm.DB, opts ...gen.DOOption) config {
  16. _config := config{}
  17. _config.configDo.UseDB(db, opts...)
  18. _config.configDo.UseModel(&model.Config{})
  19. tableName := _config.configDo.TableName()
  20. _config.ALL = field.NewAsterisk(tableName)
  21. _config.ID = field.NewInt64(tableName, "id")
  22. _config.Group_ = field.NewString(tableName, "group")
  23. _config.Name = field.NewString(tableName, "name")
  24. _config.Type = field.NewString(tableName, "type")
  25. _config.Key = field.NewString(tableName, "key")
  26. _config.Value = field.NewString(tableName, "value")
  27. _config.DefaultValue = field.NewString(tableName, "default_value")
  28. _config.Sort = field.NewInt32(tableName, "sort")
  29. _config.Tip = field.NewString(tableName, "tip")
  30. _config.IsDefault = field.NewBool(tableName, "is_default")
  31. _config.Status = field.NewBool(tableName, "status")
  32. _config.CreatedAt = field.NewTime(tableName, "created_at")
  33. _config.UpdatedAt = field.NewTime(tableName, "updated_at")
  34. _config.fillFieldMap()
  35. return _config
  36. }
  37. type config struct {
  38. configDo
  39. ALL field.Asterisk
  40. ID field.Int64 // 配置ID
  41. Group_ field.String // 分组
  42. Name field.String // 参数名称
  43. Type field.String // 类型:string,text,int,bool,array,datetime,date,file
  44. Key field.String // 参数键名
  45. Value field.String // 参数键值
  46. DefaultValue field.String // 默认值
  47. Sort field.Int32 // 排序
  48. Tip field.String // 变量描述
  49. IsDefault field.Bool // 是否默认
  50. Status field.Bool // 状态
  51. CreatedAt field.Time // 创建时间
  52. UpdatedAt field.Time // 更新时间
  53. fieldMap map[string]field.Expr
  54. }
  55. func (c config) Table(newTableName string) *config {
  56. c.configDo.UseTable(newTableName)
  57. return c.updateTableName(newTableName)
  58. }
  59. func (c config) As(alias string) *config {
  60. c.configDo.DO = *(c.configDo.As(alias).(*gen.DO))
  61. return c.updateTableName(alias)
  62. }
  63. func (c *config) updateTableName(table string) *config {
  64. c.ALL = field.NewAsterisk(table)
  65. c.ID = field.NewInt64(table, "id")
  66. c.Group_ = field.NewString(table, "group")
  67. c.Name = field.NewString(table, "name")
  68. c.Type = field.NewString(table, "type")
  69. c.Key = field.NewString(table, "key")
  70. c.Value = field.NewString(table, "value")
  71. c.DefaultValue = field.NewString(table, "default_value")
  72. c.Sort = field.NewInt32(table, "sort")
  73. c.Tip = field.NewString(table, "tip")
  74. c.IsDefault = field.NewBool(table, "is_default")
  75. c.Status = field.NewBool(table, "status")
  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 *config) 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 *config) fillFieldMap() {
  90. c.fieldMap = make(map[string]field.Expr, 13)
  91. c.fieldMap["id"] = c.ID
  92. c.fieldMap["group"] = c.Group_
  93. c.fieldMap["name"] = c.Name
  94. c.fieldMap["type"] = c.Type
  95. c.fieldMap["key"] = c.Key
  96. c.fieldMap["value"] = c.Value
  97. c.fieldMap["default_value"] = c.DefaultValue
  98. c.fieldMap["sort"] = c.Sort
  99. c.fieldMap["tip"] = c.Tip
  100. c.fieldMap["is_default"] = c.IsDefault
  101. c.fieldMap["status"] = c.Status
  102. c.fieldMap["created_at"] = c.CreatedAt
  103. c.fieldMap["updated_at"] = c.UpdatedAt
  104. }
  105. func (c config) clone(db *gorm.DB) config {
  106. c.configDo.ReplaceConnPool(db.Statement.ConnPool)
  107. return c
  108. }
  109. func (c config) replaceDB(db *gorm.DB) config {
  110. c.configDo.ReplaceDB(db)
  111. return c
  112. }
  113. type configDo struct{ gen.DO }
  114. func (c configDo) Debug() *configDo {
  115. return c.withDO(c.DO.Debug())
  116. }
  117. func (c configDo) WithContext(ctx context.Context) *configDo {
  118. return c.withDO(c.DO.WithContext(ctx))
  119. }
  120. func (c configDo) ReadDB() *configDo {
  121. return c.Clauses(dbresolver.Read)
  122. }
  123. func (c configDo) WriteDB() *configDo {
  124. return c.Clauses(dbresolver.Write)
  125. }
  126. func (c configDo) Session(config *gorm.Session) *configDo {
  127. return c.withDO(c.DO.Session(config))
  128. }
  129. func (c configDo) Clauses(conds ...clause.Expression) *configDo {
  130. return c.withDO(c.DO.Clauses(conds...))
  131. }
  132. func (c configDo) Returning(value interface{}, columns ...string) *configDo {
  133. return c.withDO(c.DO.Returning(value, columns...))
  134. }
  135. func (c configDo) Not(conds ...gen.Condition) *configDo {
  136. return c.withDO(c.DO.Not(conds...))
  137. }
  138. func (c configDo) Or(conds ...gen.Condition) *configDo {
  139. return c.withDO(c.DO.Or(conds...))
  140. }
  141. func (c configDo) Select(conds ...field.Expr) *configDo {
  142. return c.withDO(c.DO.Select(conds...))
  143. }
  144. func (c configDo) Where(conds ...gen.Condition) *configDo {
  145. return c.withDO(c.DO.Where(conds...))
  146. }
  147. func (c configDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *configDo {
  148. return c.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
  149. }
  150. func (c configDo) Order(conds ...field.Expr) *configDo {
  151. return c.withDO(c.DO.Order(conds...))
  152. }
  153. func (c configDo) Distinct(cols ...field.Expr) *configDo {
  154. return c.withDO(c.DO.Distinct(cols...))
  155. }
  156. func (c configDo) Omit(cols ...field.Expr) *configDo {
  157. return c.withDO(c.DO.Omit(cols...))
  158. }
  159. func (c configDo) Join(table schema.Tabler, on ...field.Expr) *configDo {
  160. return c.withDO(c.DO.Join(table, on...))
  161. }
  162. func (c configDo) LeftJoin(table schema.Tabler, on ...field.Expr) *configDo {
  163. return c.withDO(c.DO.LeftJoin(table, on...))
  164. }
  165. func (c configDo) RightJoin(table schema.Tabler, on ...field.Expr) *configDo {
  166. return c.withDO(c.DO.RightJoin(table, on...))
  167. }
  168. func (c configDo) Group(cols ...field.Expr) *configDo {
  169. return c.withDO(c.DO.Group(cols...))
  170. }
  171. func (c configDo) Having(conds ...gen.Condition) *configDo {
  172. return c.withDO(c.DO.Having(conds...))
  173. }
  174. func (c configDo) Limit(limit int) *configDo {
  175. return c.withDO(c.DO.Limit(limit))
  176. }
  177. func (c configDo) Offset(offset int) *configDo {
  178. return c.withDO(c.DO.Offset(offset))
  179. }
  180. func (c configDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *configDo {
  181. return c.withDO(c.DO.Scopes(funcs...))
  182. }
  183. func (c configDo) Unscoped() *configDo {
  184. return c.withDO(c.DO.Unscoped())
  185. }
  186. func (c configDo) Create(values ...*model.Config) error {
  187. if len(values) == 0 {
  188. return nil
  189. }
  190. return c.DO.Create(values)
  191. }
  192. func (c configDo) CreateInBatches(values []*model.Config, 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 configDo) Save(values ...*model.Config) error {
  198. if len(values) == 0 {
  199. return nil
  200. }
  201. return c.DO.Save(values)
  202. }
  203. func (c configDo) First() (*model.Config, error) {
  204. if result, err := c.DO.First(); err != nil {
  205. return nil, err
  206. } else {
  207. return result.(*model.Config), nil
  208. }
  209. }
  210. func (c configDo) Take() (*model.Config, error) {
  211. if result, err := c.DO.Take(); err != nil {
  212. return nil, err
  213. } else {
  214. return result.(*model.Config), nil
  215. }
  216. }
  217. func (c configDo) Last() (*model.Config, error) {
  218. if result, err := c.DO.Last(); err != nil {
  219. return nil, err
  220. } else {
  221. return result.(*model.Config), nil
  222. }
  223. }
  224. func (c configDo) Find() ([]*model.Config, error) {
  225. result, err := c.DO.Find()
  226. return result.([]*model.Config), err
  227. }
  228. func (c configDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Config, err error) {
  229. buf := make([]*model.Config, 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 configDo) FindInBatches(result *[]*model.Config, batchSize int, fc func(tx gen.Dao, batch int) error) error {
  237. return c.DO.FindInBatches(result, batchSize, fc)
  238. }
  239. func (c configDo) Attrs(attrs ...field.AssignExpr) *configDo {
  240. return c.withDO(c.DO.Attrs(attrs...))
  241. }
  242. func (c configDo) Assign(attrs ...field.AssignExpr) *configDo {
  243. return c.withDO(c.DO.Assign(attrs...))
  244. }
  245. func (c configDo) Joins(fields ...field.RelationField) *configDo {
  246. for _, _f := range fields {
  247. c = *c.withDO(c.DO.Joins(_f))
  248. }
  249. return &c
  250. }
  251. func (c configDo) Preload(fields ...field.RelationField) *configDo {
  252. for _, _f := range fields {
  253. c = *c.withDO(c.DO.Preload(_f))
  254. }
  255. return &c
  256. }
  257. func (c configDo) FirstOrInit() (*model.Config, error) {
  258. if result, err := c.DO.FirstOrInit(); err != nil {
  259. return nil, err
  260. } else {
  261. return result.(*model.Config), nil
  262. }
  263. }
  264. func (c configDo) FirstOrCreate() (*model.Config, error) {
  265. if result, err := c.DO.FirstOrCreate(); err != nil {
  266. return nil, err
  267. } else {
  268. return result.(*model.Config), nil
  269. }
  270. }
  271. func (c configDo) FindByPage(offset int, limit int) (result []*model.Config, 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 configDo) 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 configDo) Scan(result interface{}) (err error) {
  292. return c.DO.Scan(result)
  293. }
  294. func (c configDo) Delete(models ...*model.Config) (result gen.ResultInfo, err error) {
  295. return c.DO.Delete(models)
  296. }
  297. func (c *configDo) withDO(do gen.Dao) *configDo {
  298. c.DO = *do.(*gen.DO)
  299. return c
  300. }