1
0

nginx_log_indices.gen.go 12 KB

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