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

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