leaf-library-3/internal/dao/documents.gen.go
2024-12-07 02:44:32 +08:00

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