123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- // Code generated by gorm.io/gen. DO NOT EDIT.
- // Code generated by gorm.io/gen. DO NOT EDIT.
- // Code generated by gorm.io/gen. DO NOT EDIT.
- package query
- import (
- "context"
- "strings"
- "gorm.io/gorm"
- "gorm.io/gorm/clause"
- "gorm.io/gorm/schema"
- "gorm.io/gen"
- "gorm.io/gen/field"
- "gorm.io/plugin/dbresolver"
- "github.com/0xJacky/Nginx-UI/model"
- )
- func newLLMSession(db *gorm.DB, opts ...gen.DOOption) lLMSession {
- _lLMSession := lLMSession{}
- _lLMSession.lLMSessionDo.UseDB(db, opts...)
- _lLMSession.lLMSessionDo.UseModel(&model.LLMSession{})
- tableName := _lLMSession.lLMSessionDo.TableName()
- _lLMSession.ALL = field.NewAsterisk(tableName)
- _lLMSession.ID = field.NewInt(tableName, "id")
- _lLMSession.SessionID = field.NewString(tableName, "session_id")
- _lLMSession.Title = field.NewString(tableName, "title")
- _lLMSession.Path = field.NewString(tableName, "path")
- _lLMSession.SessionType = field.NewString(tableName, "session_type")
- _lLMSession.Messages = field.NewField(tableName, "messages")
- _lLMSession.MessageCount = field.NewInt(tableName, "message_count")
- _lLMSession.IsActive = field.NewBool(tableName, "is_active")
- _lLMSession.CreatedAt = field.NewTime(tableName, "created_at")
- _lLMSession.UpdatedAt = field.NewTime(tableName, "updated_at")
- _lLMSession.DeletedAt = field.NewField(tableName, "deleted_at")
- _lLMSession.fillFieldMap()
- return _lLMSession
- }
- type lLMSession struct {
- lLMSessionDo
- ALL field.Asterisk
- ID field.Int
- SessionID field.String
- Title field.String
- Path field.String
- SessionType field.String
- Messages field.Field
- MessageCount field.Int
- IsActive field.Bool
- CreatedAt field.Time
- UpdatedAt field.Time
- DeletedAt field.Field
- fieldMap map[string]field.Expr
- }
- func (l lLMSession) Table(newTableName string) *lLMSession {
- l.lLMSessionDo.UseTable(newTableName)
- return l.updateTableName(newTableName)
- }
- func (l lLMSession) As(alias string) *lLMSession {
- l.lLMSessionDo.DO = *(l.lLMSessionDo.As(alias).(*gen.DO))
- return l.updateTableName(alias)
- }
- func (l *lLMSession) updateTableName(table string) *lLMSession {
- l.ALL = field.NewAsterisk(table)
- l.ID = field.NewInt(table, "id")
- l.SessionID = field.NewString(table, "session_id")
- l.Title = field.NewString(table, "title")
- l.Path = field.NewString(table, "path")
- l.SessionType = field.NewString(table, "session_type")
- l.Messages = field.NewField(table, "messages")
- l.MessageCount = field.NewInt(table, "message_count")
- l.IsActive = field.NewBool(table, "is_active")
- l.CreatedAt = field.NewTime(table, "created_at")
- l.UpdatedAt = field.NewTime(table, "updated_at")
- l.DeletedAt = field.NewField(table, "deleted_at")
- l.fillFieldMap()
- return l
- }
- func (l *lLMSession) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
- _f, ok := l.fieldMap[fieldName]
- if !ok || _f == nil {
- return nil, false
- }
- _oe, ok := _f.(field.OrderExpr)
- return _oe, ok
- }
- func (l *lLMSession) fillFieldMap() {
- l.fieldMap = make(map[string]field.Expr, 11)
- l.fieldMap["id"] = l.ID
- l.fieldMap["session_id"] = l.SessionID
- l.fieldMap["title"] = l.Title
- l.fieldMap["path"] = l.Path
- l.fieldMap["session_type"] = l.SessionType
- l.fieldMap["messages"] = l.Messages
- l.fieldMap["message_count"] = l.MessageCount
- l.fieldMap["is_active"] = l.IsActive
- l.fieldMap["created_at"] = l.CreatedAt
- l.fieldMap["updated_at"] = l.UpdatedAt
- l.fieldMap["deleted_at"] = l.DeletedAt
- }
- func (l lLMSession) clone(db *gorm.DB) lLMSession {
- l.lLMSessionDo.ReplaceConnPool(db.Statement.ConnPool)
- return l
- }
- func (l lLMSession) replaceDB(db *gorm.DB) lLMSession {
- l.lLMSessionDo.ReplaceDB(db)
- return l
- }
- type lLMSessionDo struct{ gen.DO }
- // FirstByID Where("id=@id")
- func (l lLMSessionDo) FirstByID(id uint64) (result *model.LLMSession, err error) {
- var params []interface{}
- var generateSQL strings.Builder
- params = append(params, id)
- generateSQL.WriteString("id=? ")
- var executeSQL *gorm.DB
- executeSQL = l.UnderlyingDB().Where(generateSQL.String(), params...).Take(&result) // ignore_security_alert
- err = executeSQL.Error
- return
- }
- // DeleteByID update @@table set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=@id
- func (l lLMSessionDo) DeleteByID(id uint64) (err error) {
- var params []interface{}
- var generateSQL strings.Builder
- params = append(params, id)
- generateSQL.WriteString("update llm_sessions set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=? ")
- var executeSQL *gorm.DB
- executeSQL = l.UnderlyingDB().Exec(generateSQL.String(), params...) // ignore_security_alert
- err = executeSQL.Error
- return
- }
- func (l lLMSessionDo) Debug() *lLMSessionDo {
- return l.withDO(l.DO.Debug())
- }
- func (l lLMSessionDo) WithContext(ctx context.Context) *lLMSessionDo {
- return l.withDO(l.DO.WithContext(ctx))
- }
- func (l lLMSessionDo) ReadDB() *lLMSessionDo {
- return l.Clauses(dbresolver.Read)
- }
- func (l lLMSessionDo) WriteDB() *lLMSessionDo {
- return l.Clauses(dbresolver.Write)
- }
- func (l lLMSessionDo) Session(config *gorm.Session) *lLMSessionDo {
- return l.withDO(l.DO.Session(config))
- }
- func (l lLMSessionDo) Clauses(conds ...clause.Expression) *lLMSessionDo {
- return l.withDO(l.DO.Clauses(conds...))
- }
- func (l lLMSessionDo) Returning(value interface{}, columns ...string) *lLMSessionDo {
- return l.withDO(l.DO.Returning(value, columns...))
- }
- func (l lLMSessionDo) Not(conds ...gen.Condition) *lLMSessionDo {
- return l.withDO(l.DO.Not(conds...))
- }
- func (l lLMSessionDo) Or(conds ...gen.Condition) *lLMSessionDo {
- return l.withDO(l.DO.Or(conds...))
- }
- func (l lLMSessionDo) Select(conds ...field.Expr) *lLMSessionDo {
- return l.withDO(l.DO.Select(conds...))
- }
- func (l lLMSessionDo) Where(conds ...gen.Condition) *lLMSessionDo {
- return l.withDO(l.DO.Where(conds...))
- }
- func (l lLMSessionDo) Order(conds ...field.Expr) *lLMSessionDo {
- return l.withDO(l.DO.Order(conds...))
- }
- func (l lLMSessionDo) Distinct(cols ...field.Expr) *lLMSessionDo {
- return l.withDO(l.DO.Distinct(cols...))
- }
- func (l lLMSessionDo) Omit(cols ...field.Expr) *lLMSessionDo {
- return l.withDO(l.DO.Omit(cols...))
- }
- func (l lLMSessionDo) Join(table schema.Tabler, on ...field.Expr) *lLMSessionDo {
- return l.withDO(l.DO.Join(table, on...))
- }
- func (l lLMSessionDo) LeftJoin(table schema.Tabler, on ...field.Expr) *lLMSessionDo {
- return l.withDO(l.DO.LeftJoin(table, on...))
- }
- func (l lLMSessionDo) RightJoin(table schema.Tabler, on ...field.Expr) *lLMSessionDo {
- return l.withDO(l.DO.RightJoin(table, on...))
- }
- func (l lLMSessionDo) Group(cols ...field.Expr) *lLMSessionDo {
- return l.withDO(l.DO.Group(cols...))
- }
- func (l lLMSessionDo) Having(conds ...gen.Condition) *lLMSessionDo {
- return l.withDO(l.DO.Having(conds...))
- }
- func (l lLMSessionDo) Limit(limit int) *lLMSessionDo {
- return l.withDO(l.DO.Limit(limit))
- }
- func (l lLMSessionDo) Offset(offset int) *lLMSessionDo {
- return l.withDO(l.DO.Offset(offset))
- }
- func (l lLMSessionDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *lLMSessionDo {
- return l.withDO(l.DO.Scopes(funcs...))
- }
- func (l lLMSessionDo) Unscoped() *lLMSessionDo {
- return l.withDO(l.DO.Unscoped())
- }
- func (l lLMSessionDo) Create(values ...*model.LLMSession) error {
- if len(values) == 0 {
- return nil
- }
- return l.DO.Create(values)
- }
- func (l lLMSessionDo) CreateInBatches(values []*model.LLMSession, batchSize int) error {
- return l.DO.CreateInBatches(values, batchSize)
- }
- // Save : !!! underlying implementation is different with GORM
- // The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
- func (l lLMSessionDo) Save(values ...*model.LLMSession) error {
- if len(values) == 0 {
- return nil
- }
- return l.DO.Save(values)
- }
- func (l lLMSessionDo) First() (*model.LLMSession, error) {
- if result, err := l.DO.First(); err != nil {
- return nil, err
- } else {
- return result.(*model.LLMSession), nil
- }
- }
- func (l lLMSessionDo) Take() (*model.LLMSession, error) {
- if result, err := l.DO.Take(); err != nil {
- return nil, err
- } else {
- return result.(*model.LLMSession), nil
- }
- }
- func (l lLMSessionDo) Last() (*model.LLMSession, error) {
- if result, err := l.DO.Last(); err != nil {
- return nil, err
- } else {
- return result.(*model.LLMSession), nil
- }
- }
- func (l lLMSessionDo) Find() ([]*model.LLMSession, error) {
- result, err := l.DO.Find()
- return result.([]*model.LLMSession), err
- }
- func (l lLMSessionDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.LLMSession, err error) {
- buf := make([]*model.LLMSession, 0, batchSize)
- err = l.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
- defer func() { results = append(results, buf...) }()
- return fc(tx, batch)
- })
- return results, err
- }
- func (l lLMSessionDo) FindInBatches(result *[]*model.LLMSession, batchSize int, fc func(tx gen.Dao, batch int) error) error {
- return l.DO.FindInBatches(result, batchSize, fc)
- }
- func (l lLMSessionDo) Attrs(attrs ...field.AssignExpr) *lLMSessionDo {
- return l.withDO(l.DO.Attrs(attrs...))
- }
- func (l lLMSessionDo) Assign(attrs ...field.AssignExpr) *lLMSessionDo {
- return l.withDO(l.DO.Assign(attrs...))
- }
- func (l lLMSessionDo) Joins(fields ...field.RelationField) *lLMSessionDo {
- for _, _f := range fields {
- l = *l.withDO(l.DO.Joins(_f))
- }
- return &l
- }
- func (l lLMSessionDo) Preload(fields ...field.RelationField) *lLMSessionDo {
- for _, _f := range fields {
- l = *l.withDO(l.DO.Preload(_f))
- }
- return &l
- }
- func (l lLMSessionDo) FirstOrInit() (*model.LLMSession, error) {
- if result, err := l.DO.FirstOrInit(); err != nil {
- return nil, err
- } else {
- return result.(*model.LLMSession), nil
- }
- }
- func (l lLMSessionDo) FirstOrCreate() (*model.LLMSession, error) {
- if result, err := l.DO.FirstOrCreate(); err != nil {
- return nil, err
- } else {
- return result.(*model.LLMSession), nil
- }
- }
- func (l lLMSessionDo) FindByPage(offset int, limit int) (result []*model.LLMSession, count int64, err error) {
- result, err = l.Offset(offset).Limit(limit).Find()
- if err != nil {
- return
- }
- if size := len(result); 0 < limit && 0 < size && size < limit {
- count = int64(size + offset)
- return
- }
- count, err = l.Offset(-1).Limit(-1).Count()
- return
- }
- func (l lLMSessionDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
- count, err = l.Count()
- if err != nil {
- return
- }
- err = l.Offset(offset).Limit(limit).Scan(result)
- return
- }
- func (l lLMSessionDo) Scan(result interface{}) (err error) {
- return l.DO.Scan(result)
- }
- func (l lLMSessionDo) Delete(models ...*model.LLMSession) (result gen.ResultInfo, err error) {
- return l.DO.Delete(models)
- }
- func (l *lLMSessionDo) withDO(do gen.Dao) *lLMSessionDo {
- l.DO = *do.(*gen.DO)
- return l
- }
|