| // 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 dal |
| |
| import ( |
| "context" |
| "database/sql" |
| ) |
| |
| import ( |
| "gorm.io/gen" |
| |
| "gorm.io/gorm" |
| |
| "gorm.io/plugin/dbresolver" |
| ) |
| |
| var ( |
| Q = new(Query) |
| Commit *commit |
| CommitFile *commitFile |
| FileBlob *fileBlob |
| Repository *repository |
| Tag *tag |
| Token *token |
| User *user |
| ) |
| |
| func SetDefault(db *gorm.DB, opts ...gen.DOOption) { |
| *Q = *Use(db, opts...) |
| Commit = &Q.Commit |
| CommitFile = &Q.CommitFile |
| FileBlob = &Q.FileBlob |
| Repository = &Q.Repository |
| Tag = &Q.Tag |
| Token = &Q.Token |
| User = &Q.User |
| } |
| |
| func Use(db *gorm.DB, opts ...gen.DOOption) *Query { |
| return &Query{ |
| db: db, |
| Commit: newCommit(db, opts...), |
| CommitFile: newCommitFile(db, opts...), |
| FileBlob: newFileBlob(db, opts...), |
| Repository: newRepository(db, opts...), |
| Tag: newTag(db, opts...), |
| Token: newToken(db, opts...), |
| User: newUser(db, opts...), |
| } |
| } |
| |
| type Query struct { |
| db *gorm.DB |
| |
| Commit commit |
| CommitFile commitFile |
| FileBlob fileBlob |
| Repository repository |
| Tag tag |
| Token token |
| User user |
| } |
| |
| func (q *Query) Available() bool { return q.db != nil } |
| |
| func (q *Query) clone(db *gorm.DB) *Query { |
| return &Query{ |
| db: db, |
| Commit: q.Commit.clone(db), |
| CommitFile: q.CommitFile.clone(db), |
| FileBlob: q.FileBlob.clone(db), |
| Repository: q.Repository.clone(db), |
| Tag: q.Tag.clone(db), |
| Token: q.Token.clone(db), |
| User: q.User.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, |
| Commit: q.Commit.replaceDB(db), |
| CommitFile: q.CommitFile.replaceDB(db), |
| FileBlob: q.FileBlob.replaceDB(db), |
| Repository: q.Repository.replaceDB(db), |
| Tag: q.Tag.replaceDB(db), |
| Token: q.Token.replaceDB(db), |
| User: q.User.replaceDB(db), |
| } |
| } |
| |
| type queryCtx struct { |
| Commit ICommitDo |
| CommitFile ICommitFileDo |
| FileBlob IFileBlobDo |
| Repository IRepositoryDo |
| Tag ITagDo |
| Token ITokenDo |
| User IUserDo |
| } |
| |
| func (q *Query) WithContext(ctx context.Context) *queryCtx { |
| return &queryCtx{ |
| Commit: q.Commit.WithContext(ctx), |
| CommitFile: q.CommitFile.WithContext(ctx), |
| FileBlob: q.FileBlob.WithContext(ctx), |
| Repository: q.Repository.WithContext(ctx), |
| Tag: q.Tag.WithContext(ctx), |
| Token: q.Token.WithContext(ctx), |
| User: q.User.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 |
| } |