llm_sessions.gen.go 10 KB

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