materials.go 13 KB

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