144 lines
3.5 KiB
Go
144 lines
3.5 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"
|
|
"database/sql"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"gorm.io/gen"
|
|
|
|
"gorm.io/plugin/dbresolver"
|
|
)
|
|
|
|
var (
|
|
Q = new(Query)
|
|
BlockChunk *blockChunk
|
|
Collection *collection
|
|
Document *document
|
|
DocumentBlock *documentBlock
|
|
Workspace *workspace
|
|
WorkspaceMember *workspaceMember
|
|
)
|
|
|
|
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
|
*Q = *Use(db, opts...)
|
|
BlockChunk = &Q.BlockChunk
|
|
Collection = &Q.Collection
|
|
Document = &Q.Document
|
|
DocumentBlock = &Q.DocumentBlock
|
|
Workspace = &Q.Workspace
|
|
WorkspaceMember = &Q.WorkspaceMember
|
|
}
|
|
|
|
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
|
return &Query{
|
|
db: db,
|
|
BlockChunk: newBlockChunk(db, opts...),
|
|
Collection: newCollection(db, opts...),
|
|
Document: newDocument(db, opts...),
|
|
DocumentBlock: newDocumentBlock(db, opts...),
|
|
Workspace: newWorkspace(db, opts...),
|
|
WorkspaceMember: newWorkspaceMember(db, opts...),
|
|
}
|
|
}
|
|
|
|
type Query struct {
|
|
db *gorm.DB
|
|
|
|
BlockChunk blockChunk
|
|
Collection collection
|
|
Document document
|
|
DocumentBlock documentBlock
|
|
Workspace workspace
|
|
WorkspaceMember workspaceMember
|
|
}
|
|
|
|
func (q *Query) Available() bool { return q.db != nil }
|
|
|
|
func (q *Query) clone(db *gorm.DB) *Query {
|
|
return &Query{
|
|
db: db,
|
|
BlockChunk: q.BlockChunk.clone(db),
|
|
Collection: q.Collection.clone(db),
|
|
Document: q.Document.clone(db),
|
|
DocumentBlock: q.DocumentBlock.clone(db),
|
|
Workspace: q.Workspace.clone(db),
|
|
WorkspaceMember: q.WorkspaceMember.clone(db),
|
|
}
|
|
}
|
|
|
|
func (q *Query) ReadDB() *Query {
|
|
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
|
|
}
|
|
|
|
func (q *Query) WriteDB() *Query {
|
|
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
|
|
}
|
|
|
|
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
|
return &Query{
|
|
db: db,
|
|
BlockChunk: q.BlockChunk.replaceDB(db),
|
|
Collection: q.Collection.replaceDB(db),
|
|
Document: q.Document.replaceDB(db),
|
|
DocumentBlock: q.DocumentBlock.replaceDB(db),
|
|
Workspace: q.Workspace.replaceDB(db),
|
|
WorkspaceMember: q.WorkspaceMember.replaceDB(db),
|
|
}
|
|
}
|
|
|
|
type queryCtx struct {
|
|
BlockChunk IBlockChunkDo
|
|
Collection ICollectionDo
|
|
Document IDocumentDo
|
|
DocumentBlock IDocumentBlockDo
|
|
Workspace IWorkspaceDo
|
|
WorkspaceMember IWorkspaceMemberDo
|
|
}
|
|
|
|
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
|
return &queryCtx{
|
|
BlockChunk: q.BlockChunk.WithContext(ctx),
|
|
Collection: q.Collection.WithContext(ctx),
|
|
Document: q.Document.WithContext(ctx),
|
|
DocumentBlock: q.DocumentBlock.WithContext(ctx),
|
|
Workspace: q.Workspace.WithContext(ctx),
|
|
WorkspaceMember: q.WorkspaceMember.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
|
|
return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
|
|
}
|
|
|
|
func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
|
|
tx := q.db.Begin(opts...)
|
|
return &QueryTx{Query: q.clone(tx), Error: tx.Error}
|
|
}
|
|
|
|
type QueryTx struct {
|
|
*Query
|
|
Error error
|
|
}
|
|
|
|
func (q *QueryTx) Commit() error {
|
|
return q.db.Commit().Error
|
|
}
|
|
|
|
func (q *QueryTx) Rollback() error {
|
|
return q.db.Rollback().Error
|
|
}
|
|
|
|
func (q *QueryTx) SavePoint(name string) error {
|
|
return q.db.SavePoint(name).Error
|
|
}
|
|
|
|
func (q *QueryTx) RollbackTo(name string) error {
|
|
return q.db.RollbackTo(name).Error
|
|
}
|