/
gen.go
237 lines (215 loc) · 7.07 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
// 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"
"gorm.io/gen"
"gorm.io/gorm"
"gorm.io/plugin/dbresolver"
)
var (
Q = new(Query)
Attachment *attachment
Category *category
Comment *comment
CommentBlack *commentBlack
FlywaySchemaHistory *flywaySchemaHistory
Journal *journal
Link *link
Log *log
Menu *menu
Meta *meta
Option *option
Photo *photo
Post *post
PostCategory *postCategory
PostTag *postTag
Tag *tag
ThemeSetting *themeSetting
User *user
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
Attachment = &Q.Attachment
Category = &Q.Category
Comment = &Q.Comment
CommentBlack = &Q.CommentBlack
FlywaySchemaHistory = &Q.FlywaySchemaHistory
Journal = &Q.Journal
Link = &Q.Link
Log = &Q.Log
Menu = &Q.Menu
Meta = &Q.Meta
Option = &Q.Option
Photo = &Q.Photo
Post = &Q.Post
PostCategory = &Q.PostCategory
PostTag = &Q.PostTag
Tag = &Q.Tag
ThemeSetting = &Q.ThemeSetting
User = &Q.User
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
Attachment: newAttachment(db, opts...),
Category: newCategory(db, opts...),
Comment: newComment(db, opts...),
CommentBlack: newCommentBlack(db, opts...),
FlywaySchemaHistory: newFlywaySchemaHistory(db, opts...),
Journal: newJournal(db, opts...),
Link: newLink(db, opts...),
Log: newLog(db, opts...),
Menu: newMenu(db, opts...),
Meta: newMeta(db, opts...),
Option: newOption(db, opts...),
Photo: newPhoto(db, opts...),
Post: newPost(db, opts...),
PostCategory: newPostCategory(db, opts...),
PostTag: newPostTag(db, opts...),
Tag: newTag(db, opts...),
ThemeSetting: newThemeSetting(db, opts...),
User: newUser(db, opts...),
}
}
type Query struct {
db *gorm.DB
Attachment attachment
Category category
Comment comment
CommentBlack commentBlack
FlywaySchemaHistory flywaySchemaHistory
Journal journal
Link link
Log log
Menu menu
Meta meta
Option option
Photo photo
Post post
PostCategory postCategory
PostTag postTag
Tag tag
ThemeSetting themeSetting
User user
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
Attachment: q.Attachment.clone(db),
Category: q.Category.clone(db),
Comment: q.Comment.clone(db),
CommentBlack: q.CommentBlack.clone(db),
FlywaySchemaHistory: q.FlywaySchemaHistory.clone(db),
Journal: q.Journal.clone(db),
Link: q.Link.clone(db),
Log: q.Log.clone(db),
Menu: q.Menu.clone(db),
Meta: q.Meta.clone(db),
Option: q.Option.clone(db),
Photo: q.Photo.clone(db),
Post: q.Post.clone(db),
PostCategory: q.PostCategory.clone(db),
PostTag: q.PostTag.clone(db),
Tag: q.Tag.clone(db),
ThemeSetting: q.ThemeSetting.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,
Attachment: q.Attachment.replaceDB(db),
Category: q.Category.replaceDB(db),
Comment: q.Comment.replaceDB(db),
CommentBlack: q.CommentBlack.replaceDB(db),
FlywaySchemaHistory: q.FlywaySchemaHistory.replaceDB(db),
Journal: q.Journal.replaceDB(db),
Link: q.Link.replaceDB(db),
Log: q.Log.replaceDB(db),
Menu: q.Menu.replaceDB(db),
Meta: q.Meta.replaceDB(db),
Option: q.Option.replaceDB(db),
Photo: q.Photo.replaceDB(db),
Post: q.Post.replaceDB(db),
PostCategory: q.PostCategory.replaceDB(db),
PostTag: q.PostTag.replaceDB(db),
Tag: q.Tag.replaceDB(db),
ThemeSetting: q.ThemeSetting.replaceDB(db),
User: q.User.replaceDB(db),
}
}
type queryCtx struct {
Attachment *attachmentDo
Category *categoryDo
Comment *commentDo
CommentBlack *commentBlackDo
FlywaySchemaHistory *flywaySchemaHistoryDo
Journal *journalDo
Link *linkDo
Log *logDo
Menu *menuDo
Meta *metaDo
Option *optionDo
Photo *photoDo
Post *postDo
PostCategory *postCategoryDo
PostTag *postTagDo
Tag *tagDo
ThemeSetting *themeSettingDo
User *userDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
Attachment: q.Attachment.WithContext(ctx),
Category: q.Category.WithContext(ctx),
Comment: q.Comment.WithContext(ctx),
CommentBlack: q.CommentBlack.WithContext(ctx),
FlywaySchemaHistory: q.FlywaySchemaHistory.WithContext(ctx),
Journal: q.Journal.WithContext(ctx),
Link: q.Link.WithContext(ctx),
Log: q.Log.WithContext(ctx),
Menu: q.Menu.WithContext(ctx),
Meta: q.Meta.WithContext(ctx),
Option: q.Option.WithContext(ctx),
Photo: q.Photo.WithContext(ctx),
Post: q.Post.WithContext(ctx),
PostCategory: q.PostCategory.WithContext(ctx),
PostTag: q.PostTag.WithContext(ctx),
Tag: q.Tag.WithContext(ctx),
ThemeSetting: q.ThemeSetting.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
}