llm_sessions.gen.go 10 KB

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