425 lines
12 KiB
Go
425 lines
12 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 dao
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"gorm.io/gorm"
|
||
|
"gorm.io/gorm/clause"
|
||
|
"gorm.io/gorm/schema"
|
||
|
|
||
|
"gorm.io/gen"
|
||
|
"gorm.io/gen/field"
|
||
|
|
||
|
"gorm.io/plugin/dbresolver"
|
||
|
|
||
|
"leafdev.top/Leaf/api-platform/internal/entity"
|
||
|
)
|
||
|
|
||
|
func newApi(db *gorm.DB, opts ...gen.DOOption) api {
|
||
|
_api := api{}
|
||
|
|
||
|
_api.apiDo.UseDB(db, opts...)
|
||
|
_api.apiDo.UseModel(&entity.Api{})
|
||
|
|
||
|
tableName := _api.apiDo.TableName()
|
||
|
_api.ALL = field.NewAsterisk(tableName)
|
||
|
_api.Id = field.NewUint(tableName, "id")
|
||
|
_api.CreatedAt = field.NewTime(tableName, "created_at")
|
||
|
_api.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||
|
_api.Name = field.NewString(tableName, "name")
|
||
|
_api.Description = field.NewString(tableName, "description")
|
||
|
_api.BackendUrl = field.NewString(tableName, "backend_url")
|
||
|
_api.AuthToken = field.NewString(tableName, "auth_token")
|
||
|
_api.OwnershipVerifiedAt = field.NewTime(tableName, "ownership_verified_at")
|
||
|
_api.OwnershipVerificationToken = field.NewString(tableName, "ownership_verification_token")
|
||
|
_api.UserId = field.NewString(tableName, "user_id")
|
||
|
_api.Status = field.NewString(tableName, "status")
|
||
|
_api.DeletedAt = field.NewField(tableName, "deleted_at")
|
||
|
|
||
|
_api.fillFieldMap()
|
||
|
|
||
|
return _api
|
||
|
}
|
||
|
|
||
|
type api struct {
|
||
|
apiDo
|
||
|
|
||
|
ALL field.Asterisk
|
||
|
Id field.Uint
|
||
|
CreatedAt field.Time
|
||
|
UpdatedAt field.Time
|
||
|
Name field.String
|
||
|
Description field.String
|
||
|
BackendUrl field.String
|
||
|
AuthToken field.String
|
||
|
OwnershipVerifiedAt field.Time
|
||
|
OwnershipVerificationToken field.String
|
||
|
UserId field.String
|
||
|
Status field.String
|
||
|
DeletedAt field.Field
|
||
|
|
||
|
fieldMap map[string]field.Expr
|
||
|
}
|
||
|
|
||
|
func (a api) Table(newTableName string) *api {
|
||
|
a.apiDo.UseTable(newTableName)
|
||
|
return a.updateTableName(newTableName)
|
||
|
}
|
||
|
|
||
|
func (a api) As(alias string) *api {
|
||
|
a.apiDo.DO = *(a.apiDo.As(alias).(*gen.DO))
|
||
|
return a.updateTableName(alias)
|
||
|
}
|
||
|
|
||
|
func (a *api) updateTableName(table string) *api {
|
||
|
a.ALL = field.NewAsterisk(table)
|
||
|
a.Id = field.NewUint(table, "id")
|
||
|
a.CreatedAt = field.NewTime(table, "created_at")
|
||
|
a.UpdatedAt = field.NewTime(table, "updated_at")
|
||
|
a.Name = field.NewString(table, "name")
|
||
|
a.Description = field.NewString(table, "description")
|
||
|
a.BackendUrl = field.NewString(table, "backend_url")
|
||
|
a.AuthToken = field.NewString(table, "auth_token")
|
||
|
a.OwnershipVerifiedAt = field.NewTime(table, "ownership_verified_at")
|
||
|
a.OwnershipVerificationToken = field.NewString(table, "ownership_verification_token")
|
||
|
a.UserId = field.NewString(table, "user_id")
|
||
|
a.Status = field.NewString(table, "status")
|
||
|
a.DeletedAt = field.NewField(table, "deleted_at")
|
||
|
|
||
|
a.fillFieldMap()
|
||
|
|
||
|
return a
|
||
|
}
|
||
|
|
||
|
func (a *api) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||
|
_f, ok := a.fieldMap[fieldName]
|
||
|
if !ok || _f == nil {
|
||
|
return nil, false
|
||
|
}
|
||
|
_oe, ok := _f.(field.OrderExpr)
|
||
|
return _oe, ok
|
||
|
}
|
||
|
|
||
|
func (a *api) fillFieldMap() {
|
||
|
a.fieldMap = make(map[string]field.Expr, 12)
|
||
|
a.fieldMap["id"] = a.Id
|
||
|
a.fieldMap["created_at"] = a.CreatedAt
|
||
|
a.fieldMap["updated_at"] = a.UpdatedAt
|
||
|
a.fieldMap["name"] = a.Name
|
||
|
a.fieldMap["description"] = a.Description
|
||
|
a.fieldMap["backend_url"] = a.BackendUrl
|
||
|
a.fieldMap["auth_token"] = a.AuthToken
|
||
|
a.fieldMap["ownership_verified_at"] = a.OwnershipVerifiedAt
|
||
|
a.fieldMap["ownership_verification_token"] = a.OwnershipVerificationToken
|
||
|
a.fieldMap["user_id"] = a.UserId
|
||
|
a.fieldMap["status"] = a.Status
|
||
|
a.fieldMap["deleted_at"] = a.DeletedAt
|
||
|
}
|
||
|
|
||
|
func (a api) clone(db *gorm.DB) api {
|
||
|
a.apiDo.ReplaceConnPool(db.Statement.ConnPool)
|
||
|
return a
|
||
|
}
|
||
|
|
||
|
func (a api) replaceDB(db *gorm.DB) api {
|
||
|
a.apiDo.ReplaceDB(db)
|
||
|
return a
|
||
|
}
|
||
|
|
||
|
type apiDo struct{ gen.DO }
|
||
|
|
||
|
type IApiDo interface {
|
||
|
gen.SubQuery
|
||
|
Debug() IApiDo
|
||
|
WithContext(ctx context.Context) IApiDo
|
||
|
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||
|
ReplaceDB(db *gorm.DB)
|
||
|
ReadDB() IApiDo
|
||
|
WriteDB() IApiDo
|
||
|
As(alias string) gen.Dao
|
||
|
Session(config *gorm.Session) IApiDo
|
||
|
Columns(cols ...field.Expr) gen.Columns
|
||
|
Clauses(conds ...clause.Expression) IApiDo
|
||
|
Not(conds ...gen.Condition) IApiDo
|
||
|
Or(conds ...gen.Condition) IApiDo
|
||
|
Select(conds ...field.Expr) IApiDo
|
||
|
Where(conds ...gen.Condition) IApiDo
|
||
|
Order(conds ...field.Expr) IApiDo
|
||
|
Distinct(cols ...field.Expr) IApiDo
|
||
|
Omit(cols ...field.Expr) IApiDo
|
||
|
Join(table schema.Tabler, on ...field.Expr) IApiDo
|
||
|
LeftJoin(table schema.Tabler, on ...field.Expr) IApiDo
|
||
|
RightJoin(table schema.Tabler, on ...field.Expr) IApiDo
|
||
|
Group(cols ...field.Expr) IApiDo
|
||
|
Having(conds ...gen.Condition) IApiDo
|
||
|
Limit(limit int) IApiDo
|
||
|
Offset(offset int) IApiDo
|
||
|
Count() (count int64, err error)
|
||
|
Scopes(funcs ...func(gen.Dao) gen.Dao) IApiDo
|
||
|
Unscoped() IApiDo
|
||
|
Create(values ...*entity.Api) error
|
||
|
CreateInBatches(values []*entity.Api, batchSize int) error
|
||
|
Save(values ...*entity.Api) error
|
||
|
First() (*entity.Api, error)
|
||
|
Take() (*entity.Api, error)
|
||
|
Last() (*entity.Api, error)
|
||
|
Find() ([]*entity.Api, error)
|
||
|
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Api, err error)
|
||
|
FindInBatches(result *[]*entity.Api, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||
|
Pluck(column field.Expr, dest interface{}) error
|
||
|
Delete(...*entity.Api) (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) IApiDo
|
||
|
Assign(attrs ...field.AssignExpr) IApiDo
|
||
|
Joins(fields ...field.RelationField) IApiDo
|
||
|
Preload(fields ...field.RelationField) IApiDo
|
||
|
FirstOrInit() (*entity.Api, error)
|
||
|
FirstOrCreate() (*entity.Api, error)
|
||
|
FindByPage(offset int, limit int) (result []*entity.Api, 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) IApiDo
|
||
|
UnderlyingDB() *gorm.DB
|
||
|
schema.Tabler
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Debug() IApiDo {
|
||
|
return a.withDO(a.DO.Debug())
|
||
|
}
|
||
|
|
||
|
func (a apiDo) WithContext(ctx context.Context) IApiDo {
|
||
|
return a.withDO(a.DO.WithContext(ctx))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) ReadDB() IApiDo {
|
||
|
return a.Clauses(dbresolver.Read)
|
||
|
}
|
||
|
|
||
|
func (a apiDo) WriteDB() IApiDo {
|
||
|
return a.Clauses(dbresolver.Write)
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Session(config *gorm.Session) IApiDo {
|
||
|
return a.withDO(a.DO.Session(config))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Clauses(conds ...clause.Expression) IApiDo {
|
||
|
return a.withDO(a.DO.Clauses(conds...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Returning(value interface{}, columns ...string) IApiDo {
|
||
|
return a.withDO(a.DO.Returning(value, columns...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Not(conds ...gen.Condition) IApiDo {
|
||
|
return a.withDO(a.DO.Not(conds...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Or(conds ...gen.Condition) IApiDo {
|
||
|
return a.withDO(a.DO.Or(conds...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Select(conds ...field.Expr) IApiDo {
|
||
|
return a.withDO(a.DO.Select(conds...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Where(conds ...gen.Condition) IApiDo {
|
||
|
return a.withDO(a.DO.Where(conds...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Order(conds ...field.Expr) IApiDo {
|
||
|
return a.withDO(a.DO.Order(conds...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Distinct(cols ...field.Expr) IApiDo {
|
||
|
return a.withDO(a.DO.Distinct(cols...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Omit(cols ...field.Expr) IApiDo {
|
||
|
return a.withDO(a.DO.Omit(cols...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Join(table schema.Tabler, on ...field.Expr) IApiDo {
|
||
|
return a.withDO(a.DO.Join(table, on...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) LeftJoin(table schema.Tabler, on ...field.Expr) IApiDo {
|
||
|
return a.withDO(a.DO.LeftJoin(table, on...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) RightJoin(table schema.Tabler, on ...field.Expr) IApiDo {
|
||
|
return a.withDO(a.DO.RightJoin(table, on...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Group(cols ...field.Expr) IApiDo {
|
||
|
return a.withDO(a.DO.Group(cols...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Having(conds ...gen.Condition) IApiDo {
|
||
|
return a.withDO(a.DO.Having(conds...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Limit(limit int) IApiDo {
|
||
|
return a.withDO(a.DO.Limit(limit))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Offset(offset int) IApiDo {
|
||
|
return a.withDO(a.DO.Offset(offset))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IApiDo {
|
||
|
return a.withDO(a.DO.Scopes(funcs...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Unscoped() IApiDo {
|
||
|
return a.withDO(a.DO.Unscoped())
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Create(values ...*entity.Api) error {
|
||
|
if len(values) == 0 {
|
||
|
return nil
|
||
|
}
|
||
|
return a.DO.Create(values)
|
||
|
}
|
||
|
|
||
|
func (a apiDo) CreateInBatches(values []*entity.Api, batchSize int) error {
|
||
|
return a.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 (a apiDo) Save(values ...*entity.Api) error {
|
||
|
if len(values) == 0 {
|
||
|
return nil
|
||
|
}
|
||
|
return a.DO.Save(values)
|
||
|
}
|
||
|
|
||
|
func (a apiDo) First() (*entity.Api, error) {
|
||
|
if result, err := a.DO.First(); err != nil {
|
||
|
return nil, err
|
||
|
} else {
|
||
|
return result.(*entity.Api), nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Take() (*entity.Api, error) {
|
||
|
if result, err := a.DO.Take(); err != nil {
|
||
|
return nil, err
|
||
|
} else {
|
||
|
return result.(*entity.Api), nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Last() (*entity.Api, error) {
|
||
|
if result, err := a.DO.Last(); err != nil {
|
||
|
return nil, err
|
||
|
} else {
|
||
|
return result.(*entity.Api), nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Find() ([]*entity.Api, error) {
|
||
|
result, err := a.DO.Find()
|
||
|
return result.([]*entity.Api), err
|
||
|
}
|
||
|
|
||
|
func (a apiDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Api, err error) {
|
||
|
buf := make([]*entity.Api, 0, batchSize)
|
||
|
err = a.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 (a apiDo) FindInBatches(result *[]*entity.Api, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||
|
return a.DO.FindInBatches(result, batchSize, fc)
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Attrs(attrs ...field.AssignExpr) IApiDo {
|
||
|
return a.withDO(a.DO.Attrs(attrs...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Assign(attrs ...field.AssignExpr) IApiDo {
|
||
|
return a.withDO(a.DO.Assign(attrs...))
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Joins(fields ...field.RelationField) IApiDo {
|
||
|
for _, _f := range fields {
|
||
|
a = *a.withDO(a.DO.Joins(_f))
|
||
|
}
|
||
|
return &a
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Preload(fields ...field.RelationField) IApiDo {
|
||
|
for _, _f := range fields {
|
||
|
a = *a.withDO(a.DO.Preload(_f))
|
||
|
}
|
||
|
return &a
|
||
|
}
|
||
|
|
||
|
func (a apiDo) FirstOrInit() (*entity.Api, error) {
|
||
|
if result, err := a.DO.FirstOrInit(); err != nil {
|
||
|
return nil, err
|
||
|
} else {
|
||
|
return result.(*entity.Api), nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a apiDo) FirstOrCreate() (*entity.Api, error) {
|
||
|
if result, err := a.DO.FirstOrCreate(); err != nil {
|
||
|
return nil, err
|
||
|
} else {
|
||
|
return result.(*entity.Api), nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a apiDo) FindByPage(offset int, limit int) (result []*entity.Api, count int64, err error) {
|
||
|
result, err = a.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 = a.Offset(-1).Limit(-1).Count()
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (a apiDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||
|
count, err = a.Count()
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err = a.Offset(offset).Limit(limit).Scan(result)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Scan(result interface{}) (err error) {
|
||
|
return a.DO.Scan(result)
|
||
|
}
|
||
|
|
||
|
func (a apiDo) Delete(models ...*entity.Api) (result gen.ResultInfo, err error) {
|
||
|
return a.DO.Delete(models)
|
||
|
}
|
||
|
|
||
|
func (a *apiDo) withDO(do gen.Dao) *apiDo {
|
||
|
a.DO = *do.(*gen.DO)
|
||
|
return a
|
||
|
}
|