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