-
Notifications
You must be signed in to change notification settings - Fork 62
/
gen.go
243 lines (221 loc) · 8.27 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
// 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 query
import (
"context"
"database/sql"
"gorm.io/gorm"
"gorm.io/gen"
"gorm.io/plugin/dbresolver"
)
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
AccessToken: newAccessToken(db, opts...),
Cast: newCast(db, opts...),
Character: newCharacter(db, opts...),
CharacterSubjects: newCharacterSubjects(db, opts...),
EpCollection: newEpCollection(db, opts...),
Episode: newEpisode(db, opts...),
Friend: newFriend(db, opts...),
Index: newIndex(db, opts...),
IndexCollect: newIndexCollect(db, opts...),
IndexSubject: newIndexSubject(db, opts...),
Member: newMember(db, opts...),
Notification: newNotification(db, opts...),
NotificationField: newNotificationField(db, opts...),
Person: newPerson(db, opts...),
PersonField: newPersonField(db, opts...),
PersonSubjects: newPersonSubjects(db, opts...),
PrivateMessage: newPrivateMessage(db, opts...),
RevisionHistory: newRevisionHistory(db, opts...),
RevisionText: newRevisionText(db, opts...),
Subject: newSubject(db, opts...),
SubjectCollection: newSubjectCollection(db, opts...),
SubjectField: newSubjectField(db, opts...),
SubjectRelation: newSubjectRelation(db, opts...),
SubjectRevision: newSubjectRevision(db, opts...),
UserGroup: newUserGroup(db, opts...),
WebSession: newWebSession(db, opts...),
}
}
type Query struct {
db *gorm.DB
AccessToken accessToken
Cast cast
Character character
CharacterSubjects characterSubjects
EpCollection epCollection
Episode episode
Friend friend
Index index
IndexCollect indexCollect
IndexSubject indexSubject
Member member
Notification notification
NotificationField notificationField
Person person
PersonField personField
PersonSubjects personSubjects
PrivateMessage privateMessage
RevisionHistory revisionHistory
RevisionText revisionText
Subject subject
SubjectCollection subjectCollection
SubjectField subjectField
SubjectRelation subjectRelation
SubjectRevision subjectRevision
UserGroup userGroup
WebSession webSession
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
AccessToken: q.AccessToken.clone(db),
Cast: q.Cast.clone(db),
Character: q.Character.clone(db),
CharacterSubjects: q.CharacterSubjects.clone(db),
EpCollection: q.EpCollection.clone(db),
Episode: q.Episode.clone(db),
Friend: q.Friend.clone(db),
Index: q.Index.clone(db),
IndexCollect: q.IndexCollect.clone(db),
IndexSubject: q.IndexSubject.clone(db),
Member: q.Member.clone(db),
Notification: q.Notification.clone(db),
NotificationField: q.NotificationField.clone(db),
Person: q.Person.clone(db),
PersonField: q.PersonField.clone(db),
PersonSubjects: q.PersonSubjects.clone(db),
PrivateMessage: q.PrivateMessage.clone(db),
RevisionHistory: q.RevisionHistory.clone(db),
RevisionText: q.RevisionText.clone(db),
Subject: q.Subject.clone(db),
SubjectCollection: q.SubjectCollection.clone(db),
SubjectField: q.SubjectField.clone(db),
SubjectRelation: q.SubjectRelation.clone(db),
SubjectRevision: q.SubjectRevision.clone(db),
UserGroup: q.UserGroup.clone(db),
WebSession: q.WebSession.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,
AccessToken: q.AccessToken.replaceDB(db),
Cast: q.Cast.replaceDB(db),
Character: q.Character.replaceDB(db),
CharacterSubjects: q.CharacterSubjects.replaceDB(db),
EpCollection: q.EpCollection.replaceDB(db),
Episode: q.Episode.replaceDB(db),
Friend: q.Friend.replaceDB(db),
Index: q.Index.replaceDB(db),
IndexCollect: q.IndexCollect.replaceDB(db),
IndexSubject: q.IndexSubject.replaceDB(db),
Member: q.Member.replaceDB(db),
Notification: q.Notification.replaceDB(db),
NotificationField: q.NotificationField.replaceDB(db),
Person: q.Person.replaceDB(db),
PersonField: q.PersonField.replaceDB(db),
PersonSubjects: q.PersonSubjects.replaceDB(db),
PrivateMessage: q.PrivateMessage.replaceDB(db),
RevisionHistory: q.RevisionHistory.replaceDB(db),
RevisionText: q.RevisionText.replaceDB(db),
Subject: q.Subject.replaceDB(db),
SubjectCollection: q.SubjectCollection.replaceDB(db),
SubjectField: q.SubjectField.replaceDB(db),
SubjectRelation: q.SubjectRelation.replaceDB(db),
SubjectRevision: q.SubjectRevision.replaceDB(db),
UserGroup: q.UserGroup.replaceDB(db),
WebSession: q.WebSession.replaceDB(db),
}
}
type queryCtx struct {
AccessToken *accessTokenDo
Cast *castDo
Character *characterDo
CharacterSubjects *characterSubjectsDo
EpCollection *epCollectionDo
Episode *episodeDo
Friend *friendDo
Index *indexDo
IndexCollect *indexCollectDo
IndexSubject *indexSubjectDo
Member *memberDo
Notification *notificationDo
NotificationField *notificationFieldDo
Person *personDo
PersonField *personFieldDo
PersonSubjects *personSubjectsDo
PrivateMessage *privateMessageDo
RevisionHistory *revisionHistoryDo
RevisionText *revisionTextDo
Subject *subjectDo
SubjectCollection *subjectCollectionDo
SubjectField *subjectFieldDo
SubjectRelation *subjectRelationDo
SubjectRevision *subjectRevisionDo
UserGroup *userGroupDo
WebSession *webSessionDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
AccessToken: q.AccessToken.WithContext(ctx),
Cast: q.Cast.WithContext(ctx),
Character: q.Character.WithContext(ctx),
CharacterSubjects: q.CharacterSubjects.WithContext(ctx),
EpCollection: q.EpCollection.WithContext(ctx),
Episode: q.Episode.WithContext(ctx),
Friend: q.Friend.WithContext(ctx),
Index: q.Index.WithContext(ctx),
IndexCollect: q.IndexCollect.WithContext(ctx),
IndexSubject: q.IndexSubject.WithContext(ctx),
Member: q.Member.WithContext(ctx),
Notification: q.Notification.WithContext(ctx),
NotificationField: q.NotificationField.WithContext(ctx),
Person: q.Person.WithContext(ctx),
PersonField: q.PersonField.WithContext(ctx),
PersonSubjects: q.PersonSubjects.WithContext(ctx),
PrivateMessage: q.PrivateMessage.WithContext(ctx),
RevisionHistory: q.RevisionHistory.WithContext(ctx),
RevisionText: q.RevisionText.WithContext(ctx),
Subject: q.Subject.WithContext(ctx),
SubjectCollection: q.SubjectCollection.WithContext(ctx),
SubjectField: q.SubjectField.WithContext(ctx),
SubjectRelation: q.SubjectRelation.WithContext(ctx),
SubjectRevision: q.SubjectRevision.WithContext(ctx),
UserGroup: q.UserGroup.WithContext(ctx),
WebSession: q.WebSession.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
}