feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
111
backend/domain/modelmgr/internal/dal/query/gen.go
Normal file
111
backend/domain/modelmgr/internal/dal/query/gen.go
Normal file
@@ -0,0 +1,111 @@
|
||||
// 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"
|
||||
"database/sql"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"gorm.io/gen"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
var (
|
||||
Q = new(Query)
|
||||
ModelEntity *modelEntity
|
||||
ModelMeta *modelMeta
|
||||
)
|
||||
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
*Q = *Use(db, opts...)
|
||||
ModelEntity = &Q.ModelEntity
|
||||
ModelMeta = &Q.ModelMeta
|
||||
}
|
||||
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
ModelEntity: newModelEntity(db, opts...),
|
||||
ModelMeta: newModelMeta(db, opts...),
|
||||
}
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
ModelEntity modelEntity
|
||||
ModelMeta modelMeta
|
||||
}
|
||||
|
||||
func (q *Query) Available() bool { return q.db != nil }
|
||||
|
||||
func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
ModelEntity: q.ModelEntity.clone(db),
|
||||
ModelMeta: q.ModelMeta.clone(db),
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Query) ReadDB() *Query {
|
||||
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
|
||||
}
|
||||
|
||||
func (q *Query) WriteDB() *Query {
|
||||
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
|
||||
}
|
||||
|
||||
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
ModelEntity: q.ModelEntity.replaceDB(db),
|
||||
ModelMeta: q.ModelMeta.replaceDB(db),
|
||||
}
|
||||
}
|
||||
|
||||
type queryCtx struct {
|
||||
ModelEntity IModelEntityDo
|
||||
ModelMeta IModelMetaDo
|
||||
}
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
ModelEntity: q.ModelEntity.WithContext(ctx),
|
||||
ModelMeta: q.ModelMeta.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
|
||||
return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
|
||||
}
|
||||
|
||||
func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
|
||||
tx := q.db.Begin(opts...)
|
||||
return &QueryTx{Query: q.clone(tx), Error: tx.Error}
|
||||
}
|
||||
|
||||
type QueryTx struct {
|
||||
*Query
|
||||
Error error
|
||||
}
|
||||
|
||||
func (q *QueryTx) Commit() error {
|
||||
return q.db.Commit().Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) Rollback() error {
|
||||
return q.db.Rollback().Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) SavePoint(name string) error {
|
||||
return q.db.SavePoint(name).Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) RollbackTo(name string) error {
|
||||
return q.db.RollbackTo(name).Error
|
||||
}
|
||||
417
backend/domain/modelmgr/internal/dal/query/model_entity.gen.go
Normal file
417
backend/domain/modelmgr/internal/dal/query/model_entity.gen.go
Normal file
@@ -0,0 +1,417 @@
|
||||
// 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"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/modelmgr/internal/dal/model"
|
||||
)
|
||||
|
||||
func newModelEntity(db *gorm.DB, opts ...gen.DOOption) modelEntity {
|
||||
_modelEntity := modelEntity{}
|
||||
|
||||
_modelEntity.modelEntityDo.UseDB(db, opts...)
|
||||
_modelEntity.modelEntityDo.UseModel(&model.ModelEntity{})
|
||||
|
||||
tableName := _modelEntity.modelEntityDo.TableName()
|
||||
_modelEntity.ALL = field.NewAsterisk(tableName)
|
||||
_modelEntity.ID = field.NewInt64(tableName, "id")
|
||||
_modelEntity.MetaID = field.NewInt64(tableName, "meta_id")
|
||||
_modelEntity.Name = field.NewString(tableName, "name")
|
||||
_modelEntity.Description = field.NewString(tableName, "description")
|
||||
_modelEntity.DefaultParams = field.NewField(tableName, "default_params")
|
||||
_modelEntity.Scenario = field.NewField(tableName, "scenario")
|
||||
_modelEntity.Status = field.NewField(tableName, "status")
|
||||
_modelEntity.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_modelEntity.UpdatedAt = field.NewInt64(tableName, "updated_at")
|
||||
_modelEntity.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_modelEntity.fillFieldMap()
|
||||
|
||||
return _modelEntity
|
||||
}
|
||||
|
||||
// modelEntity 模型信息
|
||||
type modelEntity struct {
|
||||
modelEntityDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键ID
|
||||
MetaID field.Int64 // 模型元信息 id
|
||||
Name field.String // 名称
|
||||
Description field.String // 描述
|
||||
DefaultParams field.Field // 默认参数
|
||||
Scenario field.Field // 模型应用场景
|
||||
Status field.Field // 模型状态
|
||||
CreatedAt field.Int64 // Create Time in Milliseconds
|
||||
UpdatedAt field.Int64 // Update Time in Milliseconds
|
||||
DeletedAt field.Field // Delete Time in Milliseconds
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (m modelEntity) Table(newTableName string) *modelEntity {
|
||||
m.modelEntityDo.UseTable(newTableName)
|
||||
return m.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (m modelEntity) As(alias string) *modelEntity {
|
||||
m.modelEntityDo.DO = *(m.modelEntityDo.As(alias).(*gen.DO))
|
||||
return m.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (m *modelEntity) updateTableName(table string) *modelEntity {
|
||||
m.ALL = field.NewAsterisk(table)
|
||||
m.ID = field.NewInt64(table, "id")
|
||||
m.MetaID = field.NewInt64(table, "meta_id")
|
||||
m.Name = field.NewString(table, "name")
|
||||
m.Description = field.NewString(table, "description")
|
||||
m.DefaultParams = field.NewField(table, "default_params")
|
||||
m.Scenario = field.NewField(table, "scenario")
|
||||
m.Status = field.NewField(table, "status")
|
||||
m.CreatedAt = field.NewInt64(table, "created_at")
|
||||
m.UpdatedAt = field.NewInt64(table, "updated_at")
|
||||
m.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
m.fillFieldMap()
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *modelEntity) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := m.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (m *modelEntity) fillFieldMap() {
|
||||
m.fieldMap = make(map[string]field.Expr, 10)
|
||||
m.fieldMap["id"] = m.ID
|
||||
m.fieldMap["meta_id"] = m.MetaID
|
||||
m.fieldMap["name"] = m.Name
|
||||
m.fieldMap["description"] = m.Description
|
||||
m.fieldMap["default_params"] = m.DefaultParams
|
||||
m.fieldMap["scenario"] = m.Scenario
|
||||
m.fieldMap["status"] = m.Status
|
||||
m.fieldMap["created_at"] = m.CreatedAt
|
||||
m.fieldMap["updated_at"] = m.UpdatedAt
|
||||
m.fieldMap["deleted_at"] = m.DeletedAt
|
||||
}
|
||||
|
||||
func (m modelEntity) clone(db *gorm.DB) modelEntity {
|
||||
m.modelEntityDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return m
|
||||
}
|
||||
|
||||
func (m modelEntity) replaceDB(db *gorm.DB) modelEntity {
|
||||
m.modelEntityDo.ReplaceDB(db)
|
||||
return m
|
||||
}
|
||||
|
||||
type modelEntityDo struct{ gen.DO }
|
||||
|
||||
type IModelEntityDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IModelEntityDo
|
||||
WithContext(ctx context.Context) IModelEntityDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IModelEntityDo
|
||||
WriteDB() IModelEntityDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IModelEntityDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IModelEntityDo
|
||||
Not(conds ...gen.Condition) IModelEntityDo
|
||||
Or(conds ...gen.Condition) IModelEntityDo
|
||||
Select(conds ...field.Expr) IModelEntityDo
|
||||
Where(conds ...gen.Condition) IModelEntityDo
|
||||
Order(conds ...field.Expr) IModelEntityDo
|
||||
Distinct(cols ...field.Expr) IModelEntityDo
|
||||
Omit(cols ...field.Expr) IModelEntityDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IModelEntityDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IModelEntityDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IModelEntityDo
|
||||
Group(cols ...field.Expr) IModelEntityDo
|
||||
Having(conds ...gen.Condition) IModelEntityDo
|
||||
Limit(limit int) IModelEntityDo
|
||||
Offset(offset int) IModelEntityDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IModelEntityDo
|
||||
Unscoped() IModelEntityDo
|
||||
Create(values ...*model.ModelEntity) error
|
||||
CreateInBatches(values []*model.ModelEntity, batchSize int) error
|
||||
Save(values ...*model.ModelEntity) error
|
||||
First() (*model.ModelEntity, error)
|
||||
Take() (*model.ModelEntity, error)
|
||||
Last() (*model.ModelEntity, error)
|
||||
Find() ([]*model.ModelEntity, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ModelEntity, err error)
|
||||
FindInBatches(result *[]*model.ModelEntity, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.ModelEntity) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IModelEntityDo
|
||||
Assign(attrs ...field.AssignExpr) IModelEntityDo
|
||||
Joins(fields ...field.RelationField) IModelEntityDo
|
||||
Preload(fields ...field.RelationField) IModelEntityDo
|
||||
FirstOrInit() (*model.ModelEntity, error)
|
||||
FirstOrCreate() (*model.ModelEntity, error)
|
||||
FindByPage(offset int, limit int) (result []*model.ModelEntity, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IModelEntityDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Debug() IModelEntityDo {
|
||||
return m.withDO(m.DO.Debug())
|
||||
}
|
||||
|
||||
func (m modelEntityDo) WithContext(ctx context.Context) IModelEntityDo {
|
||||
return m.withDO(m.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) ReadDB() IModelEntityDo {
|
||||
return m.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (m modelEntityDo) WriteDB() IModelEntityDo {
|
||||
return m.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Session(config *gorm.Session) IModelEntityDo {
|
||||
return m.withDO(m.DO.Session(config))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Clauses(conds ...clause.Expression) IModelEntityDo {
|
||||
return m.withDO(m.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Returning(value interface{}, columns ...string) IModelEntityDo {
|
||||
return m.withDO(m.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Not(conds ...gen.Condition) IModelEntityDo {
|
||||
return m.withDO(m.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Or(conds ...gen.Condition) IModelEntityDo {
|
||||
return m.withDO(m.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Select(conds ...field.Expr) IModelEntityDo {
|
||||
return m.withDO(m.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Where(conds ...gen.Condition) IModelEntityDo {
|
||||
return m.withDO(m.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Order(conds ...field.Expr) IModelEntityDo {
|
||||
return m.withDO(m.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Distinct(cols ...field.Expr) IModelEntityDo {
|
||||
return m.withDO(m.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Omit(cols ...field.Expr) IModelEntityDo {
|
||||
return m.withDO(m.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Join(table schema.Tabler, on ...field.Expr) IModelEntityDo {
|
||||
return m.withDO(m.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) LeftJoin(table schema.Tabler, on ...field.Expr) IModelEntityDo {
|
||||
return m.withDO(m.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) RightJoin(table schema.Tabler, on ...field.Expr) IModelEntityDo {
|
||||
return m.withDO(m.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Group(cols ...field.Expr) IModelEntityDo {
|
||||
return m.withDO(m.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Having(conds ...gen.Condition) IModelEntityDo {
|
||||
return m.withDO(m.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Limit(limit int) IModelEntityDo {
|
||||
return m.withDO(m.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Offset(offset int) IModelEntityDo {
|
||||
return m.withDO(m.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IModelEntityDo {
|
||||
return m.withDO(m.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Unscoped() IModelEntityDo {
|
||||
return m.withDO(m.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Create(values ...*model.ModelEntity) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return m.DO.Create(values)
|
||||
}
|
||||
|
||||
func (m modelEntityDo) CreateInBatches(values []*model.ModelEntity, batchSize int) error {
|
||||
return m.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 (m modelEntityDo) Save(values ...*model.ModelEntity) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return m.DO.Save(values)
|
||||
}
|
||||
|
||||
func (m modelEntityDo) First() (*model.ModelEntity, error) {
|
||||
if result, err := m.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ModelEntity), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Take() (*model.ModelEntity, error) {
|
||||
if result, err := m.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ModelEntity), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Last() (*model.ModelEntity, error) {
|
||||
if result, err := m.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ModelEntity), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Find() ([]*model.ModelEntity, error) {
|
||||
result, err := m.DO.Find()
|
||||
return result.([]*model.ModelEntity), err
|
||||
}
|
||||
|
||||
func (m modelEntityDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ModelEntity, err error) {
|
||||
buf := make([]*model.ModelEntity, 0, batchSize)
|
||||
err = m.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 (m modelEntityDo) FindInBatches(result *[]*model.ModelEntity, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return m.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Attrs(attrs ...field.AssignExpr) IModelEntityDo {
|
||||
return m.withDO(m.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Assign(attrs ...field.AssignExpr) IModelEntityDo {
|
||||
return m.withDO(m.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Joins(fields ...field.RelationField) IModelEntityDo {
|
||||
for _, _f := range fields {
|
||||
m = *m.withDO(m.DO.Joins(_f))
|
||||
}
|
||||
return &m
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Preload(fields ...field.RelationField) IModelEntityDo {
|
||||
for _, _f := range fields {
|
||||
m = *m.withDO(m.DO.Preload(_f))
|
||||
}
|
||||
return &m
|
||||
}
|
||||
|
||||
func (m modelEntityDo) FirstOrInit() (*model.ModelEntity, error) {
|
||||
if result, err := m.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ModelEntity), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m modelEntityDo) FirstOrCreate() (*model.ModelEntity, error) {
|
||||
if result, err := m.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ModelEntity), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m modelEntityDo) FindByPage(offset int, limit int) (result []*model.ModelEntity, count int64, err error) {
|
||||
result, err = m.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 = m.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (m modelEntityDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = m.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = m.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Scan(result interface{}) (err error) {
|
||||
return m.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (m modelEntityDo) Delete(models ...*model.ModelEntity) (result gen.ResultInfo, err error) {
|
||||
return m.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (m *modelEntityDo) withDO(do gen.Dao) *modelEntityDo {
|
||||
m.DO = *do.(*gen.DO)
|
||||
return m
|
||||
}
|
||||
425
backend/domain/modelmgr/internal/dal/query/model_meta.gen.go
Normal file
425
backend/domain/modelmgr/internal/dal/query/model_meta.gen.go
Normal file
@@ -0,0 +1,425 @@
|
||||
// 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"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/modelmgr/internal/dal/model"
|
||||
)
|
||||
|
||||
func newModelMeta(db *gorm.DB, opts ...gen.DOOption) modelMeta {
|
||||
_modelMeta := modelMeta{}
|
||||
|
||||
_modelMeta.modelMetaDo.UseDB(db, opts...)
|
||||
_modelMeta.modelMetaDo.UseModel(&model.ModelMeta{})
|
||||
|
||||
tableName := _modelMeta.modelMetaDo.TableName()
|
||||
_modelMeta.ALL = field.NewAsterisk(tableName)
|
||||
_modelMeta.ID = field.NewInt64(tableName, "id")
|
||||
_modelMeta.ModelName = field.NewString(tableName, "model_name")
|
||||
_modelMeta.Protocol = field.NewString(tableName, "protocol")
|
||||
_modelMeta.IconURI = field.NewString(tableName, "icon_uri")
|
||||
_modelMeta.Capability = field.NewField(tableName, "capability")
|
||||
_modelMeta.ConnConfig = field.NewField(tableName, "conn_config")
|
||||
_modelMeta.Status = field.NewField(tableName, "status")
|
||||
_modelMeta.Description = field.NewString(tableName, "description")
|
||||
_modelMeta.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_modelMeta.UpdatedAt = field.NewInt64(tableName, "updated_at")
|
||||
_modelMeta.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_modelMeta.IconURL = field.NewString(tableName, "icon_url")
|
||||
|
||||
_modelMeta.fillFieldMap()
|
||||
|
||||
return _modelMeta
|
||||
}
|
||||
|
||||
// modelMeta 模型元信息
|
||||
type modelMeta struct {
|
||||
modelMetaDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键ID
|
||||
ModelName field.String // 模型名称
|
||||
Protocol field.String // 模型协议
|
||||
IconURI field.String // Icon URI
|
||||
Capability field.Field // 模型能力
|
||||
ConnConfig field.Field // 模型连接配置
|
||||
Status field.Field // 模型状态
|
||||
Description field.String // 模型描述
|
||||
CreatedAt field.Int64 // Create Time in Milliseconds
|
||||
UpdatedAt field.Int64 // Update Time in Milliseconds
|
||||
DeletedAt field.Field // Delete Time in Milliseconds
|
||||
IconURL field.String // Icon URL
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (m modelMeta) Table(newTableName string) *modelMeta {
|
||||
m.modelMetaDo.UseTable(newTableName)
|
||||
return m.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (m modelMeta) As(alias string) *modelMeta {
|
||||
m.modelMetaDo.DO = *(m.modelMetaDo.As(alias).(*gen.DO))
|
||||
return m.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (m *modelMeta) updateTableName(table string) *modelMeta {
|
||||
m.ALL = field.NewAsterisk(table)
|
||||
m.ID = field.NewInt64(table, "id")
|
||||
m.ModelName = field.NewString(table, "model_name")
|
||||
m.Protocol = field.NewString(table, "protocol")
|
||||
m.IconURI = field.NewString(table, "icon_uri")
|
||||
m.Capability = field.NewField(table, "capability")
|
||||
m.ConnConfig = field.NewField(table, "conn_config")
|
||||
m.Status = field.NewField(table, "status")
|
||||
m.Description = field.NewString(table, "description")
|
||||
m.CreatedAt = field.NewInt64(table, "created_at")
|
||||
m.UpdatedAt = field.NewInt64(table, "updated_at")
|
||||
m.DeletedAt = field.NewField(table, "deleted_at")
|
||||
m.IconURL = field.NewString(table, "icon_url")
|
||||
|
||||
m.fillFieldMap()
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *modelMeta) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := m.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (m *modelMeta) fillFieldMap() {
|
||||
m.fieldMap = make(map[string]field.Expr, 12)
|
||||
m.fieldMap["id"] = m.ID
|
||||
m.fieldMap["model_name"] = m.ModelName
|
||||
m.fieldMap["protocol"] = m.Protocol
|
||||
m.fieldMap["icon_uri"] = m.IconURI
|
||||
m.fieldMap["capability"] = m.Capability
|
||||
m.fieldMap["conn_config"] = m.ConnConfig
|
||||
m.fieldMap["status"] = m.Status
|
||||
m.fieldMap["description"] = m.Description
|
||||
m.fieldMap["created_at"] = m.CreatedAt
|
||||
m.fieldMap["updated_at"] = m.UpdatedAt
|
||||
m.fieldMap["deleted_at"] = m.DeletedAt
|
||||
m.fieldMap["icon_url"] = m.IconURL
|
||||
}
|
||||
|
||||
func (m modelMeta) clone(db *gorm.DB) modelMeta {
|
||||
m.modelMetaDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return m
|
||||
}
|
||||
|
||||
func (m modelMeta) replaceDB(db *gorm.DB) modelMeta {
|
||||
m.modelMetaDo.ReplaceDB(db)
|
||||
return m
|
||||
}
|
||||
|
||||
type modelMetaDo struct{ gen.DO }
|
||||
|
||||
type IModelMetaDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IModelMetaDo
|
||||
WithContext(ctx context.Context) IModelMetaDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IModelMetaDo
|
||||
WriteDB() IModelMetaDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IModelMetaDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IModelMetaDo
|
||||
Not(conds ...gen.Condition) IModelMetaDo
|
||||
Or(conds ...gen.Condition) IModelMetaDo
|
||||
Select(conds ...field.Expr) IModelMetaDo
|
||||
Where(conds ...gen.Condition) IModelMetaDo
|
||||
Order(conds ...field.Expr) IModelMetaDo
|
||||
Distinct(cols ...field.Expr) IModelMetaDo
|
||||
Omit(cols ...field.Expr) IModelMetaDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IModelMetaDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IModelMetaDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IModelMetaDo
|
||||
Group(cols ...field.Expr) IModelMetaDo
|
||||
Having(conds ...gen.Condition) IModelMetaDo
|
||||
Limit(limit int) IModelMetaDo
|
||||
Offset(offset int) IModelMetaDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IModelMetaDo
|
||||
Unscoped() IModelMetaDo
|
||||
Create(values ...*model.ModelMeta) error
|
||||
CreateInBatches(values []*model.ModelMeta, batchSize int) error
|
||||
Save(values ...*model.ModelMeta) error
|
||||
First() (*model.ModelMeta, error)
|
||||
Take() (*model.ModelMeta, error)
|
||||
Last() (*model.ModelMeta, error)
|
||||
Find() ([]*model.ModelMeta, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ModelMeta, err error)
|
||||
FindInBatches(result *[]*model.ModelMeta, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.ModelMeta) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IModelMetaDo
|
||||
Assign(attrs ...field.AssignExpr) IModelMetaDo
|
||||
Joins(fields ...field.RelationField) IModelMetaDo
|
||||
Preload(fields ...field.RelationField) IModelMetaDo
|
||||
FirstOrInit() (*model.ModelMeta, error)
|
||||
FirstOrCreate() (*model.ModelMeta, error)
|
||||
FindByPage(offset int, limit int) (result []*model.ModelMeta, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IModelMetaDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Debug() IModelMetaDo {
|
||||
return m.withDO(m.DO.Debug())
|
||||
}
|
||||
|
||||
func (m modelMetaDo) WithContext(ctx context.Context) IModelMetaDo {
|
||||
return m.withDO(m.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) ReadDB() IModelMetaDo {
|
||||
return m.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (m modelMetaDo) WriteDB() IModelMetaDo {
|
||||
return m.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Session(config *gorm.Session) IModelMetaDo {
|
||||
return m.withDO(m.DO.Session(config))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Clauses(conds ...clause.Expression) IModelMetaDo {
|
||||
return m.withDO(m.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Returning(value interface{}, columns ...string) IModelMetaDo {
|
||||
return m.withDO(m.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Not(conds ...gen.Condition) IModelMetaDo {
|
||||
return m.withDO(m.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Or(conds ...gen.Condition) IModelMetaDo {
|
||||
return m.withDO(m.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Select(conds ...field.Expr) IModelMetaDo {
|
||||
return m.withDO(m.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Where(conds ...gen.Condition) IModelMetaDo {
|
||||
return m.withDO(m.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Order(conds ...field.Expr) IModelMetaDo {
|
||||
return m.withDO(m.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Distinct(cols ...field.Expr) IModelMetaDo {
|
||||
return m.withDO(m.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Omit(cols ...field.Expr) IModelMetaDo {
|
||||
return m.withDO(m.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Join(table schema.Tabler, on ...field.Expr) IModelMetaDo {
|
||||
return m.withDO(m.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) LeftJoin(table schema.Tabler, on ...field.Expr) IModelMetaDo {
|
||||
return m.withDO(m.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) RightJoin(table schema.Tabler, on ...field.Expr) IModelMetaDo {
|
||||
return m.withDO(m.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Group(cols ...field.Expr) IModelMetaDo {
|
||||
return m.withDO(m.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Having(conds ...gen.Condition) IModelMetaDo {
|
||||
return m.withDO(m.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Limit(limit int) IModelMetaDo {
|
||||
return m.withDO(m.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Offset(offset int) IModelMetaDo {
|
||||
return m.withDO(m.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IModelMetaDo {
|
||||
return m.withDO(m.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Unscoped() IModelMetaDo {
|
||||
return m.withDO(m.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Create(values ...*model.ModelMeta) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return m.DO.Create(values)
|
||||
}
|
||||
|
||||
func (m modelMetaDo) CreateInBatches(values []*model.ModelMeta, batchSize int) error {
|
||||
return m.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 (m modelMetaDo) Save(values ...*model.ModelMeta) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return m.DO.Save(values)
|
||||
}
|
||||
|
||||
func (m modelMetaDo) First() (*model.ModelMeta, error) {
|
||||
if result, err := m.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ModelMeta), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Take() (*model.ModelMeta, error) {
|
||||
if result, err := m.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ModelMeta), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Last() (*model.ModelMeta, error) {
|
||||
if result, err := m.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ModelMeta), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Find() ([]*model.ModelMeta, error) {
|
||||
result, err := m.DO.Find()
|
||||
return result.([]*model.ModelMeta), err
|
||||
}
|
||||
|
||||
func (m modelMetaDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ModelMeta, err error) {
|
||||
buf := make([]*model.ModelMeta, 0, batchSize)
|
||||
err = m.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 (m modelMetaDo) FindInBatches(result *[]*model.ModelMeta, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return m.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Attrs(attrs ...field.AssignExpr) IModelMetaDo {
|
||||
return m.withDO(m.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Assign(attrs ...field.AssignExpr) IModelMetaDo {
|
||||
return m.withDO(m.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Joins(fields ...field.RelationField) IModelMetaDo {
|
||||
for _, _f := range fields {
|
||||
m = *m.withDO(m.DO.Joins(_f))
|
||||
}
|
||||
return &m
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Preload(fields ...field.RelationField) IModelMetaDo {
|
||||
for _, _f := range fields {
|
||||
m = *m.withDO(m.DO.Preload(_f))
|
||||
}
|
||||
return &m
|
||||
}
|
||||
|
||||
func (m modelMetaDo) FirstOrInit() (*model.ModelMeta, error) {
|
||||
if result, err := m.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ModelMeta), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m modelMetaDo) FirstOrCreate() (*model.ModelMeta, error) {
|
||||
if result, err := m.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ModelMeta), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m modelMetaDo) FindByPage(offset int, limit int) (result []*model.ModelMeta, count int64, err error) {
|
||||
result, err = m.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 = m.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (m modelMetaDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = m.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = m.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Scan(result interface{}) (err error) {
|
||||
return m.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (m modelMetaDo) Delete(models ...*model.ModelMeta) (result gen.ResultInfo, err error) {
|
||||
return m.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (m *modelMetaDo) withDO(do gen.Dao) *modelMetaDo {
|
||||
m.DO = *do.(*gen.DO)
|
||||
return m
|
||||
}
|
||||
Reference in New Issue
Block a user