-
Notifications
You must be signed in to change notification settings - Fork 559
/
Copy pathgen.go
159 lines (135 loc) · 4.72 KB
/
gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// 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 models_generated
import (
"context"
"database/sql"
"gorm.io/gorm"
"gorm.io/gen"
"gorm.io/plugin/dbresolver"
)
var (
Q = new(Query)
DiggerCiJob *diggerCiJob
DiggerCiJobToken *diggerCiJobToken
GithubAppInstallationLink *githubAppInstallationLink
OrgSetting *orgSetting
Organisation *organisation
Project *project
Repo *repo
User *user
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
DiggerCiJob = &Q.DiggerCiJob
DiggerCiJobToken = &Q.DiggerCiJobToken
GithubAppInstallationLink = &Q.GithubAppInstallationLink
OrgSetting = &Q.OrgSetting
Organisation = &Q.Organisation
Project = &Q.Project
Repo = &Q.Repo
User = &Q.User
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
DiggerCiJob: newDiggerCiJob(db, opts...),
DiggerCiJobToken: newDiggerCiJobToken(db, opts...),
GithubAppInstallationLink: newGithubAppInstallationLink(db, opts...),
OrgSetting: newOrgSetting(db, opts...),
Organisation: newOrganisation(db, opts...),
Project: newProject(db, opts...),
Repo: newRepo(db, opts...),
User: newUser(db, opts...),
}
}
type Query struct {
db *gorm.DB
DiggerCiJob diggerCiJob
DiggerCiJobToken diggerCiJobToken
GithubAppInstallationLink githubAppInstallationLink
OrgSetting orgSetting
Organisation organisation
Project project
Repo repo
User user
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
DiggerCiJob: q.DiggerCiJob.clone(db),
DiggerCiJobToken: q.DiggerCiJobToken.clone(db),
GithubAppInstallationLink: q.GithubAppInstallationLink.clone(db),
OrgSetting: q.OrgSetting.clone(db),
Organisation: q.Organisation.clone(db),
Project: q.Project.clone(db),
Repo: q.Repo.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,
DiggerCiJob: q.DiggerCiJob.replaceDB(db),
DiggerCiJobToken: q.DiggerCiJobToken.replaceDB(db),
GithubAppInstallationLink: q.GithubAppInstallationLink.replaceDB(db),
OrgSetting: q.OrgSetting.replaceDB(db),
Organisation: q.Organisation.replaceDB(db),
Project: q.Project.replaceDB(db),
Repo: q.Repo.replaceDB(db),
User: q.User.replaceDB(db),
}
}
type queryCtx struct {
DiggerCiJob IDiggerCiJobDo
DiggerCiJobToken IDiggerCiJobTokenDo
GithubAppInstallationLink IGithubAppInstallationLinkDo
OrgSetting IOrgSettingDo
Organisation IOrganisationDo
Project IProjectDo
Repo IRepoDo
User IUserDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
DiggerCiJob: q.DiggerCiJob.WithContext(ctx),
DiggerCiJobToken: q.DiggerCiJobToken.WithContext(ctx),
GithubAppInstallationLink: q.GithubAppInstallationLink.WithContext(ctx),
OrgSetting: q.OrgSetting.WithContext(ctx),
Organisation: q.Organisation.WithContext(ctx),
Project: q.Project.WithContext(ctx),
Repo: q.Repo.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
}