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