-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_query.go
225 lines (201 loc) · 5.53 KB
/
model_query.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
// generated by qbg -usedatastorewrapper -output model_query.go .; DO NOT EDIT
package main
import (
"go.mercari.io/datastore"
)
// Plugin supply hook point for query constructions.
type Plugin interface {
Init(typeName string)
Ancestor(ancestor datastore.Key)
KeysOnly()
Start(cur datastore.Cursor)
Offset(offset int)
Limit(limit int)
Filter(name, op string, value interface{})
Asc(name string)
Desc(name string)
}
// Plugger supply Plugin component.
type Plugger interface {
Plugin() Plugin
}
// BQLoadJobQueryBuilder build query for BQLoadJob.
type BQLoadJobQueryBuilder struct {
q datastore.Query
plugin Plugin
JobID *BQLoadJobQueryProperty
Kind *BQLoadJobQueryProperty
Status *BQLoadJobQueryProperty
ChangeStatusAt *BQLoadJobQueryProperty
CreatedAt *BQLoadJobQueryProperty
UpdatedAt *BQLoadJobQueryProperty
SchemaVersion *BQLoadJobQueryProperty
}
// BQLoadJobQueryProperty has property information for BQLoadJobQueryBuilder.
type BQLoadJobQueryProperty struct {
bldr *BQLoadJobQueryBuilder
name string
}
// NewBQLoadJobQueryBuilder create new BQLoadJobQueryBuilder.
func NewBQLoadJobQueryBuilder(client datastore.Client) *BQLoadJobQueryBuilder {
return NewBQLoadJobQueryBuilderWithKind(client, "BQLoadJob")
}
// NewBQLoadJobQueryBuilderWithKind create new BQLoadJobQueryBuilder with specific kind.
func NewBQLoadJobQueryBuilderWithKind(client datastore.Client, kind string) *BQLoadJobQueryBuilder {
q := client.NewQuery(kind)
bldr := &BQLoadJobQueryBuilder{q: q}
bldr.JobID = &BQLoadJobQueryProperty{
bldr: bldr,
name: "JobID",
}
bldr.Kind = &BQLoadJobQueryProperty{
bldr: bldr,
name: "Kind",
}
bldr.Status = &BQLoadJobQueryProperty{
bldr: bldr,
name: "Status",
}
bldr.ChangeStatusAt = &BQLoadJobQueryProperty{
bldr: bldr,
name: "ChangeStatusAt",
}
bldr.CreatedAt = &BQLoadJobQueryProperty{
bldr: bldr,
name: "CreatedAt",
}
bldr.UpdatedAt = &BQLoadJobQueryProperty{
bldr: bldr,
name: "UpdatedAt",
}
bldr.SchemaVersion = &BQLoadJobQueryProperty{
bldr: bldr,
name: "SchemaVersion",
}
if plugger, ok := interface{}(bldr).(Plugger); ok {
bldr.plugin = plugger.Plugin()
bldr.plugin.Init("BQLoadJob")
}
return bldr
}
// Ancestor sets parent key to ancestor query.
func (bldr *BQLoadJobQueryBuilder) Ancestor(parentKey datastore.Key) *BQLoadJobQueryBuilder {
bldr.q = bldr.q.Ancestor(parentKey)
if bldr.plugin != nil {
bldr.plugin.Ancestor(parentKey)
}
return bldr
}
// KeysOnly sets keys only option to query.
func (bldr *BQLoadJobQueryBuilder) KeysOnly() *BQLoadJobQueryBuilder {
bldr.q = bldr.q.KeysOnly()
if bldr.plugin != nil {
bldr.plugin.KeysOnly()
}
return bldr
}
// Start setup to query.
func (bldr *BQLoadJobQueryBuilder) Start(cur datastore.Cursor) *BQLoadJobQueryBuilder {
bldr.q = bldr.q.Start(cur)
if bldr.plugin != nil {
bldr.plugin.Start(cur)
}
return bldr
}
// Offset setup to query.
func (bldr *BQLoadJobQueryBuilder) Offset(offset int) *BQLoadJobQueryBuilder {
bldr.q = bldr.q.Offset(offset)
if bldr.plugin != nil {
bldr.plugin.Offset(offset)
}
return bldr
}
// Limit setup to query.
func (bldr *BQLoadJobQueryBuilder) Limit(limit int) *BQLoadJobQueryBuilder {
bldr.q = bldr.q.Limit(limit)
if bldr.plugin != nil {
bldr.plugin.Limit(limit)
}
return bldr
}
// Query returns *datastore.Query.
func (bldr *BQLoadJobQueryBuilder) Query() datastore.Query {
return bldr.q
}
// Filter with op & value.
func (p *BQLoadJobQueryProperty) Filter(op string, value interface{}) *BQLoadJobQueryBuilder {
switch op {
case "<=":
p.LessThanOrEqual(value)
case ">=":
p.GreaterThanOrEqual(value)
case "<":
p.LessThan(value)
case ">":
p.GreaterThan(value)
case "=":
p.Equal(value)
default:
p.bldr.q = p.bldr.q.Filter(p.name+" "+op, value) // error raised by native query
}
if p.bldr.plugin != nil {
p.bldr.plugin.Filter(p.name, op, value)
}
return p.bldr
}
// LessThanOrEqual filter with value.
func (p *BQLoadJobQueryProperty) LessThanOrEqual(value interface{}) *BQLoadJobQueryBuilder {
p.bldr.q = p.bldr.q.Filter(p.name+" <=", value)
if p.bldr.plugin != nil {
p.bldr.plugin.Filter(p.name, "<=", value)
}
return p.bldr
}
// GreaterThanOrEqual filter with value.
func (p *BQLoadJobQueryProperty) GreaterThanOrEqual(value interface{}) *BQLoadJobQueryBuilder {
p.bldr.q = p.bldr.q.Filter(p.name+" >=", value)
if p.bldr.plugin != nil {
p.bldr.plugin.Filter(p.name, ">=", value)
}
return p.bldr
}
// LessThan filter with value.
func (p *BQLoadJobQueryProperty) LessThan(value interface{}) *BQLoadJobQueryBuilder {
p.bldr.q = p.bldr.q.Filter(p.name+" <", value)
if p.bldr.plugin != nil {
p.bldr.plugin.Filter(p.name, "<", value)
}
return p.bldr
}
// GreaterThan filter with value.
func (p *BQLoadJobQueryProperty) GreaterThan(value interface{}) *BQLoadJobQueryBuilder {
p.bldr.q = p.bldr.q.Filter(p.name+" >", value)
if p.bldr.plugin != nil {
p.bldr.plugin.Filter(p.name, ">", value)
}
return p.bldr
}
// Equal filter with value.
func (p *BQLoadJobQueryProperty) Equal(value interface{}) *BQLoadJobQueryBuilder {
p.bldr.q = p.bldr.q.Filter(p.name+" =", value)
if p.bldr.plugin != nil {
p.bldr.plugin.Filter(p.name, "=", value)
}
return p.bldr
}
// Asc order.
func (p *BQLoadJobQueryProperty) Asc() *BQLoadJobQueryBuilder {
p.bldr.q = p.bldr.q.Order(p.name)
if p.bldr.plugin != nil {
p.bldr.plugin.Asc(p.name)
}
return p.bldr
}
// Desc order.
func (p *BQLoadJobQueryProperty) Desc() *BQLoadJobQueryBuilder {
p.bldr.q = p.bldr.q.Order("-" + p.name)
if p.bldr.plugin != nil {
p.bldr.plugin.Desc(p.name)
}
return p.bldr
}