393 lines
11 KiB
Go
393 lines
11 KiB
Go
// 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"
|
|
|
|
"atom/database/models"
|
|
)
|
|
|
|
func newMigration(db *gorm.DB, opts ...gen.DOOption) migration {
|
|
_migration := migration{}
|
|
|
|
_migration.migrationDo.UseDB(db, opts...)
|
|
_migration.migrationDo.UseModel(&models.Migration{})
|
|
|
|
tableName := _migration.migrationDo.TableName()
|
|
_migration.ALL = field.NewAsterisk(tableName)
|
|
_migration.ID = field.NewString(tableName, "id")
|
|
|
|
_migration.fillFieldMap()
|
|
|
|
return _migration
|
|
}
|
|
|
|
type migration struct {
|
|
migrationDo migrationDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.String
|
|
|
|
fieldMap map[string]field.Expr
|
|
}
|
|
|
|
func (m migration) Table(newTableName string) *migration {
|
|
m.migrationDo.UseTable(newTableName)
|
|
return m.updateTableName(newTableName)
|
|
}
|
|
|
|
func (m migration) As(alias string) *migration {
|
|
m.migrationDo.DO = *(m.migrationDo.As(alias).(*gen.DO))
|
|
return m.updateTableName(alias)
|
|
}
|
|
|
|
func (m *migration) updateTableName(table string) *migration {
|
|
m.ALL = field.NewAsterisk(table)
|
|
m.ID = field.NewString(table, "id")
|
|
|
|
m.fillFieldMap()
|
|
|
|
return m
|
|
}
|
|
|
|
func (m *migration) WithContext(ctx context.Context) IMigrationDo {
|
|
return m.migrationDo.WithContext(ctx)
|
|
}
|
|
|
|
func (m migration) TableName() string { return m.migrationDo.TableName() }
|
|
|
|
func (m migration) Alias() string { return m.migrationDo.Alias() }
|
|
|
|
func (m *migration) 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 *migration) fillFieldMap() {
|
|
m.fieldMap = make(map[string]field.Expr, 1)
|
|
m.fieldMap["id"] = m.ID
|
|
}
|
|
|
|
func (m migration) clone(db *gorm.DB) migration {
|
|
m.migrationDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
return m
|
|
}
|
|
|
|
func (m migration) replaceDB(db *gorm.DB) migration {
|
|
m.migrationDo.ReplaceDB(db)
|
|
return m
|
|
}
|
|
|
|
type migrationDo struct{ gen.DO }
|
|
|
|
type IMigrationDo interface {
|
|
gen.SubQuery
|
|
Debug() IMigrationDo
|
|
WithContext(ctx context.Context) IMigrationDo
|
|
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
|
ReplaceDB(db *gorm.DB)
|
|
ReadDB() IMigrationDo
|
|
WriteDB() IMigrationDo
|
|
As(alias string) gen.Dao
|
|
Session(config *gorm.Session) IMigrationDo
|
|
Columns(cols ...field.Expr) gen.Columns
|
|
Clauses(conds ...clause.Expression) IMigrationDo
|
|
Not(conds ...gen.Condition) IMigrationDo
|
|
Or(conds ...gen.Condition) IMigrationDo
|
|
Select(conds ...field.Expr) IMigrationDo
|
|
Where(conds ...gen.Condition) IMigrationDo
|
|
Order(conds ...field.Expr) IMigrationDo
|
|
Distinct(cols ...field.Expr) IMigrationDo
|
|
Omit(cols ...field.Expr) IMigrationDo
|
|
Join(table schema.Tabler, on ...field.Expr) IMigrationDo
|
|
LeftJoin(table schema.Tabler, on ...field.Expr) IMigrationDo
|
|
RightJoin(table schema.Tabler, on ...field.Expr) IMigrationDo
|
|
Group(cols ...field.Expr) IMigrationDo
|
|
Having(conds ...gen.Condition) IMigrationDo
|
|
Limit(limit int) IMigrationDo
|
|
Offset(offset int) IMigrationDo
|
|
Count() (count int64, err error)
|
|
Scopes(funcs ...func(gen.Dao) gen.Dao) IMigrationDo
|
|
Unscoped() IMigrationDo
|
|
Create(values ...*models.Migration) error
|
|
CreateInBatches(values []*models.Migration, batchSize int) error
|
|
Save(values ...*models.Migration) error
|
|
First() (*models.Migration, error)
|
|
Take() (*models.Migration, error)
|
|
Last() (*models.Migration, error)
|
|
Find() ([]*models.Migration, error)
|
|
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Migration, err error)
|
|
FindInBatches(result *[]*models.Migration, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
|
Pluck(column field.Expr, dest interface{}) error
|
|
Delete(...*models.Migration) (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) IMigrationDo
|
|
Assign(attrs ...field.AssignExpr) IMigrationDo
|
|
Joins(fields ...field.RelationField) IMigrationDo
|
|
Preload(fields ...field.RelationField) IMigrationDo
|
|
FirstOrInit() (*models.Migration, error)
|
|
FirstOrCreate() (*models.Migration, error)
|
|
FindByPage(offset int, limit int) (result []*models.Migration, 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) IMigrationDo
|
|
UnderlyingDB() *gorm.DB
|
|
schema.Tabler
|
|
}
|
|
|
|
func (m migrationDo) Debug() IMigrationDo {
|
|
return m.withDO(m.DO.Debug())
|
|
}
|
|
|
|
func (m migrationDo) WithContext(ctx context.Context) IMigrationDo {
|
|
return m.withDO(m.DO.WithContext(ctx))
|
|
}
|
|
|
|
func (m migrationDo) ReadDB() IMigrationDo {
|
|
return m.Clauses(dbresolver.Read)
|
|
}
|
|
|
|
func (m migrationDo) WriteDB() IMigrationDo {
|
|
return m.Clauses(dbresolver.Write)
|
|
}
|
|
|
|
func (m migrationDo) Session(config *gorm.Session) IMigrationDo {
|
|
return m.withDO(m.DO.Session(config))
|
|
}
|
|
|
|
func (m migrationDo) Clauses(conds ...clause.Expression) IMigrationDo {
|
|
return m.withDO(m.DO.Clauses(conds...))
|
|
}
|
|
|
|
func (m migrationDo) Returning(value interface{}, columns ...string) IMigrationDo {
|
|
return m.withDO(m.DO.Returning(value, columns...))
|
|
}
|
|
|
|
func (m migrationDo) Not(conds ...gen.Condition) IMigrationDo {
|
|
return m.withDO(m.DO.Not(conds...))
|
|
}
|
|
|
|
func (m migrationDo) Or(conds ...gen.Condition) IMigrationDo {
|
|
return m.withDO(m.DO.Or(conds...))
|
|
}
|
|
|
|
func (m migrationDo) Select(conds ...field.Expr) IMigrationDo {
|
|
return m.withDO(m.DO.Select(conds...))
|
|
}
|
|
|
|
func (m migrationDo) Where(conds ...gen.Condition) IMigrationDo {
|
|
return m.withDO(m.DO.Where(conds...))
|
|
}
|
|
|
|
func (m migrationDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) IMigrationDo {
|
|
return m.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
|
|
}
|
|
|
|
func (m migrationDo) Order(conds ...field.Expr) IMigrationDo {
|
|
return m.withDO(m.DO.Order(conds...))
|
|
}
|
|
|
|
func (m migrationDo) Distinct(cols ...field.Expr) IMigrationDo {
|
|
return m.withDO(m.DO.Distinct(cols...))
|
|
}
|
|
|
|
func (m migrationDo) Omit(cols ...field.Expr) IMigrationDo {
|
|
return m.withDO(m.DO.Omit(cols...))
|
|
}
|
|
|
|
func (m migrationDo) Join(table schema.Tabler, on ...field.Expr) IMigrationDo {
|
|
return m.withDO(m.DO.Join(table, on...))
|
|
}
|
|
|
|
func (m migrationDo) LeftJoin(table schema.Tabler, on ...field.Expr) IMigrationDo {
|
|
return m.withDO(m.DO.LeftJoin(table, on...))
|
|
}
|
|
|
|
func (m migrationDo) RightJoin(table schema.Tabler, on ...field.Expr) IMigrationDo {
|
|
return m.withDO(m.DO.RightJoin(table, on...))
|
|
}
|
|
|
|
func (m migrationDo) Group(cols ...field.Expr) IMigrationDo {
|
|
return m.withDO(m.DO.Group(cols...))
|
|
}
|
|
|
|
func (m migrationDo) Having(conds ...gen.Condition) IMigrationDo {
|
|
return m.withDO(m.DO.Having(conds...))
|
|
}
|
|
|
|
func (m migrationDo) Limit(limit int) IMigrationDo {
|
|
return m.withDO(m.DO.Limit(limit))
|
|
}
|
|
|
|
func (m migrationDo) Offset(offset int) IMigrationDo {
|
|
return m.withDO(m.DO.Offset(offset))
|
|
}
|
|
|
|
func (m migrationDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IMigrationDo {
|
|
return m.withDO(m.DO.Scopes(funcs...))
|
|
}
|
|
|
|
func (m migrationDo) Unscoped() IMigrationDo {
|
|
return m.withDO(m.DO.Unscoped())
|
|
}
|
|
|
|
func (m migrationDo) Create(values ...*models.Migration) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return m.DO.Create(values)
|
|
}
|
|
|
|
func (m migrationDo) CreateInBatches(values []*models.Migration, 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 migrationDo) Save(values ...*models.Migration) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return m.DO.Save(values)
|
|
}
|
|
|
|
func (m migrationDo) First() (*models.Migration, error) {
|
|
if result, err := m.DO.First(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Migration), nil
|
|
}
|
|
}
|
|
|
|
func (m migrationDo) Take() (*models.Migration, error) {
|
|
if result, err := m.DO.Take(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Migration), nil
|
|
}
|
|
}
|
|
|
|
func (m migrationDo) Last() (*models.Migration, error) {
|
|
if result, err := m.DO.Last(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Migration), nil
|
|
}
|
|
}
|
|
|
|
func (m migrationDo) Find() ([]*models.Migration, error) {
|
|
result, err := m.DO.Find()
|
|
return result.([]*models.Migration), err
|
|
}
|
|
|
|
func (m migrationDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Migration, err error) {
|
|
buf := make([]*models.Migration, 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 migrationDo) FindInBatches(result *[]*models.Migration, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
return m.DO.FindInBatches(result, batchSize, fc)
|
|
}
|
|
|
|
func (m migrationDo) Attrs(attrs ...field.AssignExpr) IMigrationDo {
|
|
return m.withDO(m.DO.Attrs(attrs...))
|
|
}
|
|
|
|
func (m migrationDo) Assign(attrs ...field.AssignExpr) IMigrationDo {
|
|
return m.withDO(m.DO.Assign(attrs...))
|
|
}
|
|
|
|
func (m migrationDo) Joins(fields ...field.RelationField) IMigrationDo {
|
|
for _, _f := range fields {
|
|
m = *m.withDO(m.DO.Joins(_f))
|
|
}
|
|
return &m
|
|
}
|
|
|
|
func (m migrationDo) Preload(fields ...field.RelationField) IMigrationDo {
|
|
for _, _f := range fields {
|
|
m = *m.withDO(m.DO.Preload(_f))
|
|
}
|
|
return &m
|
|
}
|
|
|
|
func (m migrationDo) FirstOrInit() (*models.Migration, error) {
|
|
if result, err := m.DO.FirstOrInit(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Migration), nil
|
|
}
|
|
}
|
|
|
|
func (m migrationDo) FirstOrCreate() (*models.Migration, error) {
|
|
if result, err := m.DO.FirstOrCreate(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Migration), nil
|
|
}
|
|
}
|
|
|
|
func (m migrationDo) FindByPage(offset int, limit int) (result []*models.Migration, 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 migrationDo) 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 migrationDo) Scan(result interface{}) (err error) {
|
|
return m.DO.Scan(result)
|
|
}
|
|
|
|
func (m migrationDo) Delete(models ...*models.Migration) (result gen.ResultInfo, err error) {
|
|
return m.DO.Delete(models)
|
|
}
|
|
|
|
func (m *migrationDo) withDO(do gen.Dao) *migrationDo {
|
|
m.DO = *do.(*gen.DO)
|
|
return m
|
|
}
|