notifications.gen.go 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. "strings"
  8. "gorm.io/gorm"
  9. "gorm.io/gorm/clause"
  10. "gorm.io/gorm/schema"
  11. "gorm.io/gen"
  12. "gorm.io/gen/field"
  13. "gorm.io/plugin/dbresolver"
  14. "github.com/0xJacky/Nginx-UI/model"
  15. )
  16. func newNotification(db *gorm.DB, opts ...gen.DOOption) notification {
  17. _notification := notification{}
  18. _notification.notificationDo.UseDB(db, opts...)
  19. _notification.notificationDo.UseModel(&model.Notification{})
  20. tableName := _notification.notificationDo.TableName()
  21. _notification.ALL = field.NewAsterisk(tableName)
  22. _notification.ID = field.NewUint64(tableName, "id")
  23. _notification.CreatedAt = field.NewTime(tableName, "created_at")
  24. _notification.UpdatedAt = field.NewTime(tableName, "updated_at")
  25. _notification.DeletedAt = field.NewField(tableName, "deleted_at")
  26. _notification.Type = field.NewInt(tableName, "type")
  27. _notification.Title = field.NewString(tableName, "title")
  28. _notification.Details = field.NewString(tableName, "details")
  29. _notification.fillFieldMap()
  30. return _notification
  31. }
  32. type notification struct {
  33. notificationDo
  34. ALL field.Asterisk
  35. ID field.Uint64
  36. CreatedAt field.Time
  37. UpdatedAt field.Time
  38. DeletedAt field.Field
  39. Type field.Int
  40. Title field.String
  41. Details field.String
  42. fieldMap map[string]field.Expr
  43. }
  44. func (n notification) Table(newTableName string) *notification {
  45. n.notificationDo.UseTable(newTableName)
  46. return n.updateTableName(newTableName)
  47. }
  48. func (n notification) As(alias string) *notification {
  49. n.notificationDo.DO = *(n.notificationDo.As(alias).(*gen.DO))
  50. return n.updateTableName(alias)
  51. }
  52. func (n *notification) updateTableName(table string) *notification {
  53. n.ALL = field.NewAsterisk(table)
  54. n.ID = field.NewUint64(table, "id")
  55. n.CreatedAt = field.NewTime(table, "created_at")
  56. n.UpdatedAt = field.NewTime(table, "updated_at")
  57. n.DeletedAt = field.NewField(table, "deleted_at")
  58. n.Type = field.NewInt(table, "type")
  59. n.Title = field.NewString(table, "title")
  60. n.Details = field.NewString(table, "details")
  61. n.fillFieldMap()
  62. return n
  63. }
  64. func (n *notification) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
  65. _f, ok := n.fieldMap[fieldName]
  66. if !ok || _f == nil {
  67. return nil, false
  68. }
  69. _oe, ok := _f.(field.OrderExpr)
  70. return _oe, ok
  71. }
  72. func (n *notification) fillFieldMap() {
  73. n.fieldMap = make(map[string]field.Expr, 7)
  74. n.fieldMap["id"] = n.ID
  75. n.fieldMap["created_at"] = n.CreatedAt
  76. n.fieldMap["updated_at"] = n.UpdatedAt
  77. n.fieldMap["deleted_at"] = n.DeletedAt
  78. n.fieldMap["type"] = n.Type
  79. n.fieldMap["title"] = n.Title
  80. n.fieldMap["details"] = n.Details
  81. }
  82. func (n notification) clone(db *gorm.DB) notification {
  83. n.notificationDo.ReplaceConnPool(db.Statement.ConnPool)
  84. return n
  85. }
  86. func (n notification) replaceDB(db *gorm.DB) notification {
  87. n.notificationDo.ReplaceDB(db)
  88. return n
  89. }
  90. type notificationDo struct{ gen.DO }
  91. // FirstByID Where("id=@id")
  92. func (n notificationDo) FirstByID(id uint64) (result *model.Notification, err error) {
  93. var params []interface{}
  94. var generateSQL strings.Builder
  95. params = append(params, id)
  96. generateSQL.WriteString("id=? ")
  97. var executeSQL *gorm.DB
  98. executeSQL = n.UnderlyingDB().Where(generateSQL.String(), params...).Take(&result) // ignore_security_alert
  99. err = executeSQL.Error
  100. return
  101. }
  102. // DeleteByID update @@table set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=@id
  103. func (n notificationDo) DeleteByID(id uint64) (err error) {
  104. var params []interface{}
  105. var generateSQL strings.Builder
  106. params = append(params, id)
  107. generateSQL.WriteString("update notifications set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=? ")
  108. var executeSQL *gorm.DB
  109. executeSQL = n.UnderlyingDB().Exec(generateSQL.String(), params...) // ignore_security_alert
  110. err = executeSQL.Error
  111. return
  112. }
  113. func (n notificationDo) Debug() *notificationDo {
  114. return n.withDO(n.DO.Debug())
  115. }
  116. func (n notificationDo) WithContext(ctx context.Context) *notificationDo {
  117. return n.withDO(n.DO.WithContext(ctx))
  118. }
  119. func (n notificationDo) ReadDB() *notificationDo {
  120. return n.Clauses(dbresolver.Read)
  121. }
  122. func (n notificationDo) WriteDB() *notificationDo {
  123. return n.Clauses(dbresolver.Write)
  124. }
  125. func (n notificationDo) Session(config *gorm.Session) *notificationDo {
  126. return n.withDO(n.DO.Session(config))
  127. }
  128. func (n notificationDo) Clauses(conds ...clause.Expression) *notificationDo {
  129. return n.withDO(n.DO.Clauses(conds...))
  130. }
  131. func (n notificationDo) Returning(value interface{}, columns ...string) *notificationDo {
  132. return n.withDO(n.DO.Returning(value, columns...))
  133. }
  134. func (n notificationDo) Not(conds ...gen.Condition) *notificationDo {
  135. return n.withDO(n.DO.Not(conds...))
  136. }
  137. func (n notificationDo) Or(conds ...gen.Condition) *notificationDo {
  138. return n.withDO(n.DO.Or(conds...))
  139. }
  140. func (n notificationDo) Select(conds ...field.Expr) *notificationDo {
  141. return n.withDO(n.DO.Select(conds...))
  142. }
  143. func (n notificationDo) Where(conds ...gen.Condition) *notificationDo {
  144. return n.withDO(n.DO.Where(conds...))
  145. }
  146. func (n notificationDo) Order(conds ...field.Expr) *notificationDo {
  147. return n.withDO(n.DO.Order(conds...))
  148. }
  149. func (n notificationDo) Distinct(cols ...field.Expr) *notificationDo {
  150. return n.withDO(n.DO.Distinct(cols...))
  151. }
  152. func (n notificationDo) Omit(cols ...field.Expr) *notificationDo {
  153. return n.withDO(n.DO.Omit(cols...))
  154. }
  155. func (n notificationDo) Join(table schema.Tabler, on ...field.Expr) *notificationDo {
  156. return n.withDO(n.DO.Join(table, on...))
  157. }
  158. func (n notificationDo) LeftJoin(table schema.Tabler, on ...field.Expr) *notificationDo {
  159. return n.withDO(n.DO.LeftJoin(table, on...))
  160. }
  161. func (n notificationDo) RightJoin(table schema.Tabler, on ...field.Expr) *notificationDo {
  162. return n.withDO(n.DO.RightJoin(table, on...))
  163. }
  164. func (n notificationDo) Group(cols ...field.Expr) *notificationDo {
  165. return n.withDO(n.DO.Group(cols...))
  166. }
  167. func (n notificationDo) Having(conds ...gen.Condition) *notificationDo {
  168. return n.withDO(n.DO.Having(conds...))
  169. }
  170. func (n notificationDo) Limit(limit int) *notificationDo {
  171. return n.withDO(n.DO.Limit(limit))
  172. }
  173. func (n notificationDo) Offset(offset int) *notificationDo {
  174. return n.withDO(n.DO.Offset(offset))
  175. }
  176. func (n notificationDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *notificationDo {
  177. return n.withDO(n.DO.Scopes(funcs...))
  178. }
  179. func (n notificationDo) Unscoped() *notificationDo {
  180. return n.withDO(n.DO.Unscoped())
  181. }
  182. func (n notificationDo) Create(values ...*model.Notification) error {
  183. if len(values) == 0 {
  184. return nil
  185. }
  186. return n.DO.Create(values)
  187. }
  188. func (n notificationDo) CreateInBatches(values []*model.Notification, batchSize int) error {
  189. return n.DO.CreateInBatches(values, batchSize)
  190. }
  191. // Save : !!! underlying implementation is different with GORM
  192. // The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
  193. func (n notificationDo) Save(values ...*model.Notification) error {
  194. if len(values) == 0 {
  195. return nil
  196. }
  197. return n.DO.Save(values)
  198. }
  199. func (n notificationDo) First() (*model.Notification, error) {
  200. if result, err := n.DO.First(); err != nil {
  201. return nil, err
  202. } else {
  203. return result.(*model.Notification), nil
  204. }
  205. }
  206. func (n notificationDo) Take() (*model.Notification, error) {
  207. if result, err := n.DO.Take(); err != nil {
  208. return nil, err
  209. } else {
  210. return result.(*model.Notification), nil
  211. }
  212. }
  213. func (n notificationDo) Last() (*model.Notification, error) {
  214. if result, err := n.DO.Last(); err != nil {
  215. return nil, err
  216. } else {
  217. return result.(*model.Notification), nil
  218. }
  219. }
  220. func (n notificationDo) Find() ([]*model.Notification, error) {
  221. result, err := n.DO.Find()
  222. return result.([]*model.Notification), err
  223. }
  224. func (n notificationDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Notification, err error) {
  225. buf := make([]*model.Notification, 0, batchSize)
  226. err = n.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
  227. defer func() { results = append(results, buf...) }()
  228. return fc(tx, batch)
  229. })
  230. return results, err
  231. }
  232. func (n notificationDo) FindInBatches(result *[]*model.Notification, batchSize int, fc func(tx gen.Dao, batch int) error) error {
  233. return n.DO.FindInBatches(result, batchSize, fc)
  234. }
  235. func (n notificationDo) Attrs(attrs ...field.AssignExpr) *notificationDo {
  236. return n.withDO(n.DO.Attrs(attrs...))
  237. }
  238. func (n notificationDo) Assign(attrs ...field.AssignExpr) *notificationDo {
  239. return n.withDO(n.DO.Assign(attrs...))
  240. }
  241. func (n notificationDo) Joins(fields ...field.RelationField) *notificationDo {
  242. for _, _f := range fields {
  243. n = *n.withDO(n.DO.Joins(_f))
  244. }
  245. return &n
  246. }
  247. func (n notificationDo) Preload(fields ...field.RelationField) *notificationDo {
  248. for _, _f := range fields {
  249. n = *n.withDO(n.DO.Preload(_f))
  250. }
  251. return &n
  252. }
  253. func (n notificationDo) FirstOrInit() (*model.Notification, error) {
  254. if result, err := n.DO.FirstOrInit(); err != nil {
  255. return nil, err
  256. } else {
  257. return result.(*model.Notification), nil
  258. }
  259. }
  260. func (n notificationDo) FirstOrCreate() (*model.Notification, error) {
  261. if result, err := n.DO.FirstOrCreate(); err != nil {
  262. return nil, err
  263. } else {
  264. return result.(*model.Notification), nil
  265. }
  266. }
  267. func (n notificationDo) FindByPage(offset int, limit int) (result []*model.Notification, count int64, err error) {
  268. result, err = n.Offset(offset).Limit(limit).Find()
  269. if err != nil {
  270. return
  271. }
  272. if size := len(result); 0 < limit && 0 < size && size < limit {
  273. count = int64(size + offset)
  274. return
  275. }
  276. count, err = n.Offset(-1).Limit(-1).Count()
  277. return
  278. }
  279. func (n notificationDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
  280. count, err = n.Count()
  281. if err != nil {
  282. return
  283. }
  284. err = n.Offset(offset).Limit(limit).Scan(result)
  285. return
  286. }
  287. func (n notificationDo) Scan(result interface{}) (err error) {
  288. return n.DO.Scan(result)
  289. }
  290. func (n notificationDo) Delete(models ...*model.Notification) (result gen.ResultInfo, err error) {
  291. return n.DO.Delete(models)
  292. }
  293. func (n *notificationDo) withDO(do gen.Dao) *notificationDo {
  294. n.DO = *do.(*gen.DO)
  295. return n
  296. }