-
Notifications
You must be signed in to change notification settings - Fork 49
/
custom_primitive_type.yo.go
393 lines (364 loc) · 14.2 KB
/
custom_primitive_type.yo.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
// Code generated by yo. DO NOT EDIT.
// Package models contains the types.
package models
import (
"context"
"fmt"
"cloud.google.com/go/spanner"
"google.golang.org/grpc/codes"
)
// CustomPrimitiveType represents a row from 'CustomPrimitiveTypes'.
type CustomPrimitiveType struct {
PKey string `spanner:"PKey" json:"PKey"` // PKey
FTInt64 int64 `spanner:"FTInt64" json:"FTInt64"` // FTInt64
FTInt64null int64 `spanner:"FTInt64Null" json:"FTInt64Null"` // FTInt64Null
FTInt32 int32 `spanner:"FTInt32" json:"FTInt32"` // FTInt32
FTInt32null int32 `spanner:"FTInt32Null" json:"FTInt32Null"` // FTInt32Null
FTInt16 int16 `spanner:"FTInt16" json:"FTInt16"` // FTInt16
FTInt16null int16 `spanner:"FTInt16Null" json:"FTInt16Null"` // FTInt16Null
FTInt8 int8 `spanner:"FTInt8" json:"FTInt8"` // FTInt8
FTInt8null int8 `spanner:"FTInt8Null" json:"FTInt8Null"` // FTInt8Null
FTUInt64 uint64 `spanner:"FTUInt64" json:"FTUInt64"` // FTUInt64
FTUInt64null uint64 `spanner:"FTUInt64Null" json:"FTUInt64Null"` // FTUInt64Null
FTUInt32 uint32 `spanner:"FTUInt32" json:"FTUInt32"` // FTUInt32
FTUInt32null uint32 `spanner:"FTUInt32Null" json:"FTUInt32Null"` // FTUInt32Null
FTUInt16 uint16 `spanner:"FTUInt16" json:"FTUInt16"` // FTUInt16
FTUInt16null uint16 `spanner:"FTUInt16Null" json:"FTUInt16Null"` // FTUInt16Null
FTUInt8 uint8 `spanner:"FTUInt8" json:"FTUInt8"` // FTUInt8
FTUInt8null uint8 `spanner:"FTUInt8Null" json:"FTUInt8Null"` // FTUInt8Null
FTArrayInt64 []int64 `spanner:"FTArrayInt64" json:"FTArrayInt64"` // FTArrayInt64
FTArrayInt64null []int64 `spanner:"FTArrayInt64Null" json:"FTArrayInt64Null"` // FTArrayInt64Null
FTArrayInt32 []int64 `spanner:"FTArrayInt32" json:"FTArrayInt32"` // FTArrayInt32
FTArrayInt32null []int64 `spanner:"FTArrayInt32Null" json:"FTArrayInt32Null"` // FTArrayInt32Null
FTArrayInt16 []int64 `spanner:"FTArrayInt16" json:"FTArrayInt16"` // FTArrayInt16
FTArrayInt16null []int64 `spanner:"FTArrayInt16Null" json:"FTArrayInt16Null"` // FTArrayInt16Null
FTArrayInt8 []int64 `spanner:"FTArrayInt8" json:"FTArrayInt8"` // FTArrayInt8
FTArrayInt8null []int64 `spanner:"FTArrayInt8Null" json:"FTArrayInt8Null"` // FTArrayInt8Null
FTArrayUINt64 []int64 `spanner:"FTArrayUInt64" json:"FTArrayUInt64"` // FTArrayUInt64
FTArrayUINt64null []int64 `spanner:"FTArrayUInt64Null" json:"FTArrayUInt64Null"` // FTArrayUInt64Null
FTArrayUINt32 []int64 `spanner:"FTArrayUInt32" json:"FTArrayUInt32"` // FTArrayUInt32
FTArrayUINt32null []int64 `spanner:"FTArrayUInt32Null" json:"FTArrayUInt32Null"` // FTArrayUInt32Null
FTArrayUINt16 []int64 `spanner:"FTArrayUInt16" json:"FTArrayUInt16"` // FTArrayUInt16
FTArrayUINt16null []int64 `spanner:"FTArrayUInt16Null" json:"FTArrayUInt16Null"` // FTArrayUInt16Null
FTArrayUINt8 []int64 `spanner:"FTArrayUInt8" json:"FTArrayUInt8"` // FTArrayUInt8
FTArrayUINt8null []int64 `spanner:"FTArrayUInt8Null" json:"FTArrayUInt8Null"` // FTArrayUInt8Null
}
func CustomPrimitiveTypePrimaryKeys() []string {
return []string{
"PKey",
}
}
func CustomPrimitiveTypeColumns() []string {
return []string{
"PKey",
"FTInt64",
"FTInt64Null",
"FTInt32",
"FTInt32Null",
"FTInt16",
"FTInt16Null",
"FTInt8",
"FTInt8Null",
"FTUInt64",
"FTUInt64Null",
"FTUInt32",
"FTUInt32Null",
"FTUInt16",
"FTUInt16Null",
"FTUInt8",
"FTUInt8Null",
"FTArrayInt64",
"FTArrayInt64Null",
"FTArrayInt32",
"FTArrayInt32Null",
"FTArrayInt16",
"FTArrayInt16Null",
"FTArrayInt8",
"FTArrayInt8Null",
"FTArrayUInt64",
"FTArrayUInt64Null",
"FTArrayUInt32",
"FTArrayUInt32Null",
"FTArrayUInt16",
"FTArrayUInt16Null",
"FTArrayUInt8",
"FTArrayUInt8Null",
}
}
func CustomPrimitiveTypeWritableColumns() []string {
return []string{
"PKey",
"FTInt64",
"FTInt64Null",
"FTInt32",
"FTInt32Null",
"FTInt16",
"FTInt16Null",
"FTInt8",
"FTInt8Null",
"FTUInt64",
"FTUInt64Null",
"FTUInt32",
"FTUInt32Null",
"FTUInt16",
"FTUInt16Null",
"FTUInt8",
"FTUInt8Null",
"FTArrayInt64",
"FTArrayInt64Null",
"FTArrayInt32",
"FTArrayInt32Null",
"FTArrayInt16",
"FTArrayInt16Null",
"FTArrayInt8",
"FTArrayInt8Null",
"FTArrayUInt64",
"FTArrayUInt64Null",
"FTArrayUInt32",
"FTArrayUInt32Null",
"FTArrayUInt16",
"FTArrayUInt16Null",
"FTArrayUInt8",
"FTArrayUInt8Null",
}
}
func (cpt *CustomPrimitiveType) columnsToPtrs(cols []string) ([]interface{}, error) {
ret := make([]interface{}, 0, len(cols))
for _, col := range cols {
switch col {
case "PKey":
ret = append(ret, yoDecode(&cpt.PKey))
case "FTInt64":
ret = append(ret, yoDecode(&cpt.FTInt64))
case "FTInt64Null":
ret = append(ret, yoDecode(&cpt.FTInt64null))
case "FTInt32":
ret = append(ret, yoDecode(&cpt.FTInt32))
case "FTInt32Null":
ret = append(ret, yoDecode(&cpt.FTInt32null))
case "FTInt16":
ret = append(ret, yoDecode(&cpt.FTInt16))
case "FTInt16Null":
ret = append(ret, yoDecode(&cpt.FTInt16null))
case "FTInt8":
ret = append(ret, yoDecode(&cpt.FTInt8))
case "FTInt8Null":
ret = append(ret, yoDecode(&cpt.FTInt8null))
case "FTUInt64":
ret = append(ret, yoDecode(&cpt.FTUInt64))
case "FTUInt64Null":
ret = append(ret, yoDecode(&cpt.FTUInt64null))
case "FTUInt32":
ret = append(ret, yoDecode(&cpt.FTUInt32))
case "FTUInt32Null":
ret = append(ret, yoDecode(&cpt.FTUInt32null))
case "FTUInt16":
ret = append(ret, yoDecode(&cpt.FTUInt16))
case "FTUInt16Null":
ret = append(ret, yoDecode(&cpt.FTUInt16null))
case "FTUInt8":
ret = append(ret, yoDecode(&cpt.FTUInt8))
case "FTUInt8Null":
ret = append(ret, yoDecode(&cpt.FTUInt8null))
case "FTArrayInt64":
ret = append(ret, yoDecode(&cpt.FTArrayInt64))
case "FTArrayInt64Null":
ret = append(ret, yoDecode(&cpt.FTArrayInt64null))
case "FTArrayInt32":
ret = append(ret, yoDecode(&cpt.FTArrayInt32))
case "FTArrayInt32Null":
ret = append(ret, yoDecode(&cpt.FTArrayInt32null))
case "FTArrayInt16":
ret = append(ret, yoDecode(&cpt.FTArrayInt16))
case "FTArrayInt16Null":
ret = append(ret, yoDecode(&cpt.FTArrayInt16null))
case "FTArrayInt8":
ret = append(ret, yoDecode(&cpt.FTArrayInt8))
case "FTArrayInt8Null":
ret = append(ret, yoDecode(&cpt.FTArrayInt8null))
case "FTArrayUInt64":
ret = append(ret, yoDecode(&cpt.FTArrayUINt64))
case "FTArrayUInt64Null":
ret = append(ret, yoDecode(&cpt.FTArrayUINt64null))
case "FTArrayUInt32":
ret = append(ret, yoDecode(&cpt.FTArrayUINt32))
case "FTArrayUInt32Null":
ret = append(ret, yoDecode(&cpt.FTArrayUINt32null))
case "FTArrayUInt16":
ret = append(ret, yoDecode(&cpt.FTArrayUINt16))
case "FTArrayUInt16Null":
ret = append(ret, yoDecode(&cpt.FTArrayUINt16null))
case "FTArrayUInt8":
ret = append(ret, yoDecode(&cpt.FTArrayUINt8))
case "FTArrayUInt8Null":
ret = append(ret, yoDecode(&cpt.FTArrayUINt8null))
default:
return nil, fmt.Errorf("unknown column: %s", col)
}
}
return ret, nil
}
func (cpt *CustomPrimitiveType) columnsToValues(cols []string) ([]interface{}, error) {
ret := make([]interface{}, 0, len(cols))
for _, col := range cols {
switch col {
case "PKey":
ret = append(ret, yoEncode(cpt.PKey))
case "FTInt64":
ret = append(ret, yoEncode(cpt.FTInt64))
case "FTInt64Null":
ret = append(ret, yoEncode(cpt.FTInt64null))
case "FTInt32":
ret = append(ret, yoEncode(cpt.FTInt32))
case "FTInt32Null":
ret = append(ret, yoEncode(cpt.FTInt32null))
case "FTInt16":
ret = append(ret, yoEncode(cpt.FTInt16))
case "FTInt16Null":
ret = append(ret, yoEncode(cpt.FTInt16null))
case "FTInt8":
ret = append(ret, yoEncode(cpt.FTInt8))
case "FTInt8Null":
ret = append(ret, yoEncode(cpt.FTInt8null))
case "FTUInt64":
ret = append(ret, yoEncode(cpt.FTUInt64))
case "FTUInt64Null":
ret = append(ret, yoEncode(cpt.FTUInt64null))
case "FTUInt32":
ret = append(ret, yoEncode(cpt.FTUInt32))
case "FTUInt32Null":
ret = append(ret, yoEncode(cpt.FTUInt32null))
case "FTUInt16":
ret = append(ret, yoEncode(cpt.FTUInt16))
case "FTUInt16Null":
ret = append(ret, yoEncode(cpt.FTUInt16null))
case "FTUInt8":
ret = append(ret, yoEncode(cpt.FTUInt8))
case "FTUInt8Null":
ret = append(ret, yoEncode(cpt.FTUInt8null))
case "FTArrayInt64":
ret = append(ret, yoEncode(cpt.FTArrayInt64))
case "FTArrayInt64Null":
ret = append(ret, yoEncode(cpt.FTArrayInt64null))
case "FTArrayInt32":
ret = append(ret, yoEncode(cpt.FTArrayInt32))
case "FTArrayInt32Null":
ret = append(ret, yoEncode(cpt.FTArrayInt32null))
case "FTArrayInt16":
ret = append(ret, yoEncode(cpt.FTArrayInt16))
case "FTArrayInt16Null":
ret = append(ret, yoEncode(cpt.FTArrayInt16null))
case "FTArrayInt8":
ret = append(ret, yoEncode(cpt.FTArrayInt8))
case "FTArrayInt8Null":
ret = append(ret, yoEncode(cpt.FTArrayInt8null))
case "FTArrayUInt64":
ret = append(ret, yoEncode(cpt.FTArrayUINt64))
case "FTArrayUInt64Null":
ret = append(ret, yoEncode(cpt.FTArrayUINt64null))
case "FTArrayUInt32":
ret = append(ret, yoEncode(cpt.FTArrayUINt32))
case "FTArrayUInt32Null":
ret = append(ret, yoEncode(cpt.FTArrayUINt32null))
case "FTArrayUInt16":
ret = append(ret, yoEncode(cpt.FTArrayUINt16))
case "FTArrayUInt16Null":
ret = append(ret, yoEncode(cpt.FTArrayUINt16null))
case "FTArrayUInt8":
ret = append(ret, yoEncode(cpt.FTArrayUINt8))
case "FTArrayUInt8Null":
ret = append(ret, yoEncode(cpt.FTArrayUINt8null))
default:
return nil, fmt.Errorf("unknown column: %s", col)
}
}
return ret, nil
}
// newCustomPrimitiveType_Decoder returns a decoder which reads a row from *spanner.Row
// into CustomPrimitiveType. The decoder is not goroutine-safe. Don't use it concurrently.
func newCustomPrimitiveType_Decoder(cols []string) func(*spanner.Row) (*CustomPrimitiveType, error) {
return func(row *spanner.Row) (*CustomPrimitiveType, error) {
var cpt CustomPrimitiveType
ptrs, err := cpt.columnsToPtrs(cols)
if err != nil {
return nil, err
}
if err := row.Columns(ptrs...); err != nil {
return nil, err
}
return &cpt, nil
}
}
// Insert returns a Mutation to insert a row into a table. If the row already
// exists, the write or transaction fails.
func (cpt *CustomPrimitiveType) Insert(ctx context.Context) *spanner.Mutation {
values, _ := cpt.columnsToValues(CustomPrimitiveTypeWritableColumns())
return spanner.Insert("CustomPrimitiveTypes", CustomPrimitiveTypeWritableColumns(), values)
}
// Update returns a Mutation to update a row in a table. If the row does not
// already exist, the write or transaction fails.
func (cpt *CustomPrimitiveType) Update(ctx context.Context) *spanner.Mutation {
values, _ := cpt.columnsToValues(CustomPrimitiveTypeWritableColumns())
return spanner.Update("CustomPrimitiveTypes", CustomPrimitiveTypeWritableColumns(), values)
}
// InsertOrUpdate returns a Mutation to insert a row into a table. If the row
// already exists, it updates it instead. Any column values not explicitly
// written are preserved.
func (cpt *CustomPrimitiveType) InsertOrUpdate(ctx context.Context) *spanner.Mutation {
values, _ := cpt.columnsToValues(CustomPrimitiveTypeWritableColumns())
return spanner.InsertOrUpdate("CustomPrimitiveTypes", CustomPrimitiveTypeWritableColumns(), values)
}
// Replace returns a Mutation to insert a row into a table, deleting any
// existing row. Unlike InsertOrUpdate, this means any values not explicitly
// written become NULL.
func (cpt *CustomPrimitiveType) Replace(ctx context.Context) *spanner.Mutation {
values, _ := cpt.columnsToValues(CustomPrimitiveTypeWritableColumns())
return spanner.Replace("CustomPrimitiveTypes", CustomPrimitiveTypeWritableColumns(), values)
}
// UpdateColumns returns a Mutation to update specified columns of a row in a table.
func (cpt *CustomPrimitiveType) UpdateColumns(ctx context.Context, cols ...string) (*spanner.Mutation, error) {
// add primary keys to columns to update by primary keys
colsWithPKeys := append(cols, CustomPrimitiveTypePrimaryKeys()...)
values, err := cpt.columnsToValues(colsWithPKeys)
if err != nil {
return nil, newErrorWithCode(codes.InvalidArgument, "CustomPrimitiveType.UpdateColumns", "CustomPrimitiveTypes", err)
}
return spanner.Update("CustomPrimitiveTypes", colsWithPKeys, values), nil
}
// FindCustomPrimitiveType gets a CustomPrimitiveType by primary key
func FindCustomPrimitiveType(ctx context.Context, db YODB, pKey string) (*CustomPrimitiveType, error) {
_key := spanner.Key{yoEncode(pKey)}
row, err := db.ReadRow(ctx, "CustomPrimitiveTypes", _key, CustomPrimitiveTypeColumns())
if err != nil {
return nil, newError("FindCustomPrimitiveType", "CustomPrimitiveTypes", err)
}
decoder := newCustomPrimitiveType_Decoder(CustomPrimitiveTypeColumns())
cpt, err := decoder(row)
if err != nil {
return nil, newErrorWithCode(codes.Internal, "FindCustomPrimitiveType", "CustomPrimitiveTypes", err)
}
return cpt, nil
}
// ReadCustomPrimitiveType retrieves multiples rows from CustomPrimitiveType by KeySet as a slice.
func ReadCustomPrimitiveType(ctx context.Context, db YODB, keys spanner.KeySet) ([]*CustomPrimitiveType, error) {
var res []*CustomPrimitiveType
decoder := newCustomPrimitiveType_Decoder(CustomPrimitiveTypeColumns())
rows := db.Read(ctx, "CustomPrimitiveTypes", keys, CustomPrimitiveTypeColumns())
err := rows.Do(func(row *spanner.Row) error {
cpt, err := decoder(row)
if err != nil {
return err
}
res = append(res, cpt)
return nil
})
if err != nil {
return nil, newErrorWithCode(codes.Internal, "ReadCustomPrimitiveType", "CustomPrimitiveTypes", err)
}
return res, nil
}
// Delete deletes the CustomPrimitiveType from the database.
func (cpt *CustomPrimitiveType) Delete(ctx context.Context) *spanner.Mutation {
values, _ := cpt.columnsToValues(CustomPrimitiveTypePrimaryKeys())
return spanner.Delete("CustomPrimitiveTypes", spanner.Key(values))
}