forked from tcncloud/protoc-gen-persist
/
basic_example.persist.go
2742 lines (2469 loc) · 74.4 KB
/
basic_example.persist.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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is generated by protoc-gen-persist
// Source File: tests/spanner/basic/basic_example.proto
// DO NOT EDIT !
package basic
import (
fmt "fmt"
io "io"
spanner "cloud.google.com/go/spanner"
proto "github.com/golang/protobuf/proto"
timestamp "github.com/golang/protobuf/ptypes/timestamp"
persist "github.com/tcncloud/protoc-gen-persist/persist"
test "github.com/tcncloud/protoc-gen-persist/tests/test"
context "golang.org/x/net/context"
iterator "google.golang.org/api/iterator"
codes "google.golang.org/grpc/codes"
gstatus "google.golang.org/grpc/status"
)
type Result interface {
LastInsertId() (int64, error)
RowsAffected() (int64, error)
}
type SpannerResult struct {
// TODO shouldn't be an iter
iter *spanner.RowIterator
}
func (sr *SpannerResult) LastInsertId() (int64, error) {
// sr.iter.QueryStats or sr.iter.QueryPlan
return -1, nil
}
func (sr *SpannerResult) RowsAffected() (int64, error) {
// Execution statistics for the query. Available after RowIterator.Next returns iterator.Done
return sr.iter.RowCount, nil
}
// Queries_ExtraSrv holds all the queries found the proto service option as methods
type Queries_ExtraSrv struct {
opts Opts_ExtraSrv
}
// QueriesExtraSrv returns all the known 'SQL' queires for the 'ExtraSrv' service.
// If no opts are provided default implementations are used.
func QueriesExtraSrv(opts ...Opts_ExtraSrv) *Queries_ExtraSrv {
var myOpts Opts_ExtraSrv
if len(opts) > 0 {
myOpts = opts[0]
} else {
myOpts = OptsExtraSrv(&DefaultHooks_ExtraSrv{}, &DefaultTypeMappings_ExtraSrv{})
}
return &Queries_ExtraSrv{
opts: myOpts,
}
}
// Extra returns a struct that will perform the 'extra' query.
// When Execute is called, it will use the following fields:
// []
func (this *Queries_ExtraSrv) Extra(ctx context.Context, db persist.SpannerRunnable) *Query_ExtraSrv_Extra {
return &Query_ExtraSrv_Extra{
opts: this.opts,
ctx: ctx,
db: db,
}
}
// Query_ExtraSrv_Extra (future doc string needed)
type Query_ExtraSrv_Extra struct {
opts Opts_ExtraSrv
db persist.SpannerRunnable
ctx context.Context
}
func (this *Query_ExtraSrv_Extra) QueryInType_Empty() {}
func (this *Query_ExtraSrv_Extra) QueryOutType_HasTimestamp() {}
// Executes the query 'extra' with parameters retrieved from x.
// Fields used: []
func (this *Query_ExtraSrv_Extra) Execute(x In_ExtraSrv_Extra) *Iter_ExtraSrv_Extra {
ctx := this.ctx
result := &Iter_ExtraSrv_Extra{
result: &SpannerResult{},
tm: this.opts.MAPPINGS,
ctx: ctx,
}
params, err := func() (map[string]interface{}, error) {
result := make(map[string]interface{})
return result, nil
}()
if err != nil {
result.err = err
return result
}
iter := this.db.QueryWithStats(ctx, spanner.Statement{
SQL: "SELECT * FROM extra_unary",
Params: params,
})
result.rows = iter
result.err = err
return result
}
type Iter_ExtraSrv_Extra struct {
result *SpannerResult
rows *spanner.RowIterator
err error
tm TypeMappings_ExtraSrv
ctx context.Context
}
func (this *Iter_ExtraSrv_Extra) IterOutTypeHasTimestamp() {}
func (this *Iter_ExtraSrv_Extra) IterInTypeEmpty() {}
// Each performs 'fun' on each row in the result set.
// Each respects the context passed to it.
// It will stop iteration, and returns this.ctx.Err() if encountered.
func (this *Iter_ExtraSrv_Extra) Each(fun func(*Row_ExtraSrv_Extra) error) error {
for {
select {
case <-this.ctx.Done():
return this.ctx.Err()
default:
if row, ok := this.Next(); !ok {
return nil
} else if err := fun(row); err != nil {
return err
}
}
}
}
// One returns the sole row, or ensures an error if there was not one result when this row is converted
func (this *Iter_ExtraSrv_Extra) One() *Row_ExtraSrv_Extra {
first, hasFirst := this.Next()
if first != nil && first.err != nil {
return &Row_ExtraSrv_Extra{err: first.err}
}
_, hasSecond := this.Next()
if !hasFirst || hasSecond {
amount := "none"
if hasSecond {
amount = "multiple"
}
return &Row_ExtraSrv_Extra{err: fmt.Errorf("expected exactly 1 result from query 'Extra' found %s", amount)}
}
return first
}
// Zero returns an error if there were any rows in the result
func (this *Iter_ExtraSrv_Extra) Zero() error {
row, ok := this.Next()
if row != nil && row.err != nil {
return row.err
}
if ok {
return fmt.Errorf("expected exactly 0 results from query 'Extra'")
}
return nil
}
// Next returns the next scanned row out of the database, or (nil, false) if there are no more rows
func (this *Iter_ExtraSrv_Extra) Next() (*Row_ExtraSrv_Extra, bool) {
row, err := this.rows.Next()
_ = row
if err == iterator.Done {
return nil, false
}
if err != nil {
return &Row_ExtraSrv_Extra{err: err}, true
}
time := ×tamp.Timestamp{}
timeBytes := make([]byte, 0)
if err := row.ColumnByName("time", &timeBytes); err != nil {
return &Row_ExtraSrv_Extra{err: fmt.Errorf("failed to convert db column time to []byte")}, true
}
if err := proto.Unmarshal(timeBytes, time); err != nil {
return &Row_ExtraSrv_Extra{err: fmt.Errorf("failed to unmarshal column time to proto message")}, true
}
some := &Something{}
someBytes := make([]byte, 0)
if err := row.ColumnByName("some", &someBytes); err != nil {
return &Row_ExtraSrv_Extra{err: fmt.Errorf("failed to convert db column some to []byte")}, true
}
if err := proto.Unmarshal(someBytes, some); err != nil {
return &Row_ExtraSrv_Extra{err: fmt.Errorf("failed to unmarshal column some to proto message")}, true
}
var str string
if err := row.ColumnByName("str", &str); err != nil {
return &Row_ExtraSrv_Extra{err: fmt.Errorf("cant convert db column str to protobuf go type string")}, true
}
table := &test.ExampleTable{}
tableBytes := make([]byte, 0)
if err := row.ColumnByName("table", &tableBytes); err != nil {
return &Row_ExtraSrv_Extra{err: fmt.Errorf("failed to convert db column table to []byte")}, true
}
if err := proto.Unmarshal(tableBytes, table); err != nil {
return &Row_ExtraSrv_Extra{err: fmt.Errorf("failed to unmarshal column table to proto message")}, true
}
var strs []string
if err := row.ColumnByName("strs", &strs); err != nil {
return &Row_ExtraSrv_Extra{err: fmt.Errorf("cant convert db column strs to protobuf go type []string")}, true
}
tables := make([]*test.ExampleTable, 0)
tablesBytes := make([][]byte, 0)
if err := row.ColumnByName("tables", &tablesBytes); err != nil {
return &Row_ExtraSrv_Extra{err: fmt.Errorf("failed to convert db column tables to [][]byte")}, true
}
for _, x := range tablesBytes {
tmp := &test.ExampleTable{}
if err := proto.Unmarshal(x, tmp); err != nil {
return &Row_ExtraSrv_Extra{err: fmt.Errorf("failed to unmarshal column table to proto message")}, true
}
tables = append(tables, tmp)
}
somes := make([]*Something, 0)
somesBytes := make([][]byte, 0)
if err := row.ColumnByName("somes", &somesBytes); err != nil {
return &Row_ExtraSrv_Extra{err: fmt.Errorf("failed to convert db column somes to [][]byte")}, true
}
for _, x := range somesBytes {
tmp := &Something{}
if err := proto.Unmarshal(x, tmp); err != nil {
return &Row_ExtraSrv_Extra{err: fmt.Errorf("failed to unmarshal column table to proto message")}, true
}
somes = append(somes, tmp)
}
times := make([]*timestamp.Timestamp, 0)
timesBytes := make([][]byte, 0)
if err := row.ColumnByName("times", ×Bytes); err != nil {
return &Row_ExtraSrv_Extra{err: fmt.Errorf("failed to convert db column times to [][]byte")}, true
}
for _, x := range timesBytes {
tmp := ×tamp.Timestamp{}
if err := proto.Unmarshal(x, tmp); err != nil {
return &Row_ExtraSrv_Extra{err: fmt.Errorf("failed to unmarshal column table to proto message")}, true
}
times = append(times, tmp)
}
res := &HasTimestamp{
Time: time,
Some: some,
Str: str,
Table: table,
Strs: strs,
Tables: tables,
Somes: somes,
Times: times,
}
return &Row_ExtraSrv_Extra{item: res}, true
}
// Slice returns all rows found in the iterator as a Slice.
func (this *Iter_ExtraSrv_Extra) Slice() []*Row_ExtraSrv_Extra {
var results []*Row_ExtraSrv_Extra
for {
if i, ok := this.Next(); ok {
results = append(results, i)
} else {
break
}
}
return results
}
type In_ExtraSrv_Extra interface {
}
type Out_ExtraSrv_Extra interface {
GetTime() *timestamp.Timestamp
GetSome() *Something
GetStr() string
GetTable() *test.ExampleTable
GetStrs() []string
GetTables() []*test.ExampleTable
GetSomes() []*Something
GetTimes() []*timestamp.Timestamp
}
type Row_ExtraSrv_Extra struct {
item Out_ExtraSrv_Extra
err error
}
func newRowExtraSrvExtra(item Out_ExtraSrv_Extra, err error) *Row_ExtraSrv_Extra {
return &Row_ExtraSrv_Extra{item, err}
}
// Unwrap takes an address to a proto.Message as its only parameter
// Unwrap can only set into output protos of that match method return types + the out option on the query itself
func (this *Row_ExtraSrv_Extra) Unwrap(pointerToMsg proto.Message) error {
if this.err != nil {
return this.err
}
if o, ok := (pointerToMsg).(*HasTimestamp); ok {
if o == nil {
return fmt.Errorf("must initialize *HasTimestamp before giving to Unwrap()")
}
res, _ := this.HasTimestamp()
_ = res
o.Time = res.Time
o.Some = res.Some
o.Str = res.Str
o.Table = res.Table
o.Strs = res.Strs
o.Tables = res.Tables
o.Somes = res.Somes
o.Times = res.Times
return nil
}
if o, ok := (pointerToMsg).(*test.ExampleTable); ok {
if o == nil {
return fmt.Errorf("must initialize *test.ExampleTable before giving to Unwrap()")
}
res, _ := this.TestExampleTable()
_ = res
return nil
}
return nil
}
func (this *Row_ExtraSrv_Extra) HasTimestamp() (*HasTimestamp, error) {
if this.err != nil {
return nil, this.err
}
return &HasTimestamp{
Time: this.item.GetTime(),
Some: this.item.GetSome(),
Str: this.item.GetStr(),
Table: this.item.GetTable(),
Strs: this.item.GetStrs(),
Tables: this.item.GetTables(),
Somes: this.item.GetSomes(),
Times: this.item.GetTimes(),
}, nil
}
func (this *Row_ExtraSrv_Extra) TestExampleTable() (*test.ExampleTable, error) {
if this.err != nil {
return nil, this.err
}
return &test.ExampleTable{}, nil
}
func (this *Row_ExtraSrv_Extra) Proto() (*HasTimestamp, error) {
if this.err != nil {
return nil, this.err
}
return &HasTimestamp{
Time: this.item.GetTime(),
Some: this.item.GetSome(),
Str: this.item.GetStr(),
Table: this.item.GetTable(),
Strs: this.item.GetStrs(),
Tables: this.item.GetTables(),
Somes: this.item.GetSomes(),
Times: this.item.GetTimes(),
}, nil
}
type Hooks_ExtraSrv interface {
}
type DefaultHooks_ExtraSrv struct{}
type TypeMappings_ExtraSrv interface {
}
type DefaultTypeMappings_ExtraSrv struct{}
type Opts_ExtraSrv struct {
MAPPINGS TypeMappings_ExtraSrv
HOOKS Hooks_ExtraSrv
}
func OptsExtraSrv(hooks Hooks_ExtraSrv, mappings TypeMappings_ExtraSrv) Opts_ExtraSrv {
opts := Opts_ExtraSrv{
HOOKS: &DefaultHooks_ExtraSrv{},
MAPPINGS: &DefaultTypeMappings_ExtraSrv{},
}
if hooks != nil {
opts.HOOKS = hooks
}
if mappings != nil {
opts.MAPPINGS = mappings
}
return opts
}
type Impl_ExtraSrv struct {
opts *Opts_ExtraSrv
QUERIES *Queries_ExtraSrv
HANDLERS RestOfHandlers_ExtraSrv
DB *spanner.Client
}
func ImplExtraSrv(db *spanner.Client, handlers RestOfHandlers_ExtraSrv, opts ...Opts_ExtraSrv) *Impl_ExtraSrv {
var myOpts Opts_ExtraSrv
if len(opts) > 0 {
myOpts = opts[0]
} else {
myOpts = OptsExtraSrv(&DefaultHooks_ExtraSrv{}, &DefaultTypeMappings_ExtraSrv{})
}
return &Impl_ExtraSrv{
opts: &myOpts,
QUERIES: QueriesExtraSrv(myOpts),
DB: db,
HANDLERS: handlers,
}
}
type RestOfHandlers_ExtraSrv interface {
ExtraMethod(context.Context, *test.ExampleTable) (*test.ExampleTable, error)
}
func (this *Impl_ExtraSrv) ExtraMethod(ctx context.Context, req *test.ExampleTable) (*test.ExampleTable, error) {
return this.HANDLERS.ExtraMethod(ctx, req)
}
func (this *Impl_ExtraSrv) ExtraUnary(ctx context.Context, req *test.NumRows) (*test.ExampleTable, error) {
query := this.QUERIES.Extra(ctx, this.DB.Single())
result := query.Execute(req)
res, err := result.One().TestExampleTable()
if err != nil {
return nil, err
}
return res, nil
}
// Queries_MySpanner holds all the queries found the proto service option as methods
type Queries_MySpanner struct {
opts Opts_MySpanner
}
// QueriesMySpanner returns all the known 'SQL' queires for the 'MySpanner' service.
// If no opts are provided default implementations are used.
func QueriesMySpanner(opts ...Opts_MySpanner) *Queries_MySpanner {
var myOpts Opts_MySpanner
if len(opts) > 0 {
myOpts = opts[0]
} else {
myOpts = OptsMySpanner(&DefaultHooks_MySpanner{}, &DefaultTypeMappings_MySpanner{})
}
return &Queries_MySpanner{
opts: myOpts,
}
}
// Insert returns a struct that will perform the 'insert' query.
// When Execute is called, it will use the following fields:
// [id start_time]
func (this *Queries_MySpanner) Insert(ctx context.Context, db persist.SpannerRunnable) *Query_MySpanner_Insert {
return &Query_MySpanner_Insert{
opts: this.opts,
ctx: ctx,
db: db,
}
}
// Query_MySpanner_Insert (future doc string needed)
type Query_MySpanner_Insert struct {
opts Opts_MySpanner
db persist.SpannerRunnable
ctx context.Context
}
func (this *Query_MySpanner_Insert) QueryInType_ExampleTable() {}
func (this *Query_MySpanner_Insert) QueryOutType_Empty() {}
// Executes the query 'insert' with parameters retrieved from x.
// Fields used: [id start_time]
func (this *Query_MySpanner_Insert) Execute(x In_MySpanner_Insert) *Iter_MySpanner_Insert {
ctx := this.ctx
result := &Iter_MySpanner_Insert{
result: &SpannerResult{},
tm: this.opts.MAPPINGS,
ctx: ctx,
}
params, err := func() (map[string]interface{}, error) {
result := make(map[string]interface{})
result["id"] = x.GetId()
start_time, err := proto.Marshal(x.GetStartTime())
if err != nil {
return nil, err
}
result["start_time"] = start_time
return result, nil
}()
if err != nil {
result.err = err
return result
}
iter := this.db.QueryWithStats(ctx, spanner.Statement{
SQL: "Insert into example_table (id, start_time, name) Values (@id, @start_time, 'bananas')",
Params: params,
})
result.rows = iter
result.err = err
return result
}
// Select returns a struct that will perform the 'select' query.
// When Execute is called, it will use the following fields:
// [id name]
func (this *Queries_MySpanner) Select(ctx context.Context, db persist.SpannerRunnable) *Query_MySpanner_Select {
return &Query_MySpanner_Select{
opts: this.opts,
ctx: ctx,
db: db,
}
}
// Query_MySpanner_Select (future doc string needed)
type Query_MySpanner_Select struct {
opts Opts_MySpanner
db persist.SpannerRunnable
ctx context.Context
}
func (this *Query_MySpanner_Select) QueryInType_ExampleTable() {}
func (this *Query_MySpanner_Select) QueryOutType_ExampleTable() {}
// Executes the query 'select' with parameters retrieved from x.
// Fields used: [id name]
func (this *Query_MySpanner_Select) Execute(x In_MySpanner_Select) *Iter_MySpanner_Select {
ctx := this.ctx
result := &Iter_MySpanner_Select{
result: &SpannerResult{},
tm: this.opts.MAPPINGS,
ctx: ctx,
}
params, err := func() (map[string]interface{}, error) {
result := make(map[string]interface{})
result["id"] = x.GetId()
result["name"] = x.GetName()
return result, nil
}()
if err != nil {
result.err = err
return result
}
iter := this.db.QueryWithStats(ctx, spanner.Statement{
SQL: "SELECT * from example_table Where id=@id AND name=@name",
Params: params,
})
result.rows = iter
result.err = err
return result
}
// SelectIndex returns a struct that will perform the 'select_index' query.
// When Execute is called, it will use the following fields:
// [id name]
func (this *Queries_MySpanner) SelectIndex(ctx context.Context, db persist.SpannerRunnable) *Query_MySpanner_SelectIndex {
return &Query_MySpanner_SelectIndex{
opts: this.opts,
ctx: ctx,
db: db,
}
}
// Query_MySpanner_SelectIndex (future doc string needed)
type Query_MySpanner_SelectIndex struct {
opts Opts_MySpanner
db persist.SpannerRunnable
ctx context.Context
}
func (this *Query_MySpanner_SelectIndex) QueryInType_ExampleTable() {}
func (this *Query_MySpanner_SelectIndex) QueryOutType_ExampleTable() {}
// Executes the query 'select_index' with parameters retrieved from x.
// Fields used: [id name]
func (this *Query_MySpanner_SelectIndex) Execute(x In_MySpanner_SelectIndex) *Iter_MySpanner_SelectIndex {
ctx := this.ctx
result := &Iter_MySpanner_SelectIndex{
result: &SpannerResult{},
tm: this.opts.MAPPINGS,
ctx: ctx,
}
params, err := func() (map[string]interface{}, error) {
result := make(map[string]interface{})
result["id"] = x.GetId()
result["name"] = x.GetName()
return result, nil
}()
if err != nil {
result.err = err
return result
}
iter := this.db.QueryWithStats(ctx, spanner.Statement{
SQL: "SELECT * from example_table@{FORCE_INDEX=index} Where id=@id AND name=@name",
Params: params,
})
result.rows = iter
result.err = err
return result
}
// Update returns a struct that will perform the 'update' query.
// When Execute is called, it will use the following fields:
// [start_time id]
func (this *Queries_MySpanner) Update(ctx context.Context, db persist.SpannerRunnable) *Query_MySpanner_Update {
return &Query_MySpanner_Update{
opts: this.opts,
ctx: ctx,
db: db,
}
}
// Query_MySpanner_Update (future doc string needed)
type Query_MySpanner_Update struct {
opts Opts_MySpanner
db persist.SpannerRunnable
ctx context.Context
}
func (this *Query_MySpanner_Update) QueryInType_ExampleTable() {}
func (this *Query_MySpanner_Update) QueryOutType_Empty() {}
// Executes the query 'update' with parameters retrieved from x.
// Fields used: [start_time id]
func (this *Query_MySpanner_Update) Execute(x In_MySpanner_Update) *Iter_MySpanner_Update {
ctx := this.ctx
result := &Iter_MySpanner_Update{
result: &SpannerResult{},
tm: this.opts.MAPPINGS,
ctx: ctx,
}
params, err := func() (map[string]interface{}, error) {
result := make(map[string]interface{})
start_time, err := proto.Marshal(x.GetStartTime())
if err != nil {
return nil, err
}
result["start_time"] = start_time
result["id"] = x.GetId()
return result, nil
}()
if err != nil {
result.err = err
return result
}
iter := this.db.QueryWithStats(ctx, spanner.Statement{
SQL: "Update example_table set start_time=@start_time, name='oranges' PrimaryKey(id=@id)",
Params: params,
})
result.rows = iter
result.err = err
return result
}
// Delete returns a struct that will perform the 'delete' query.
// When Execute is called, it will use the following fields:
// [start_id end_id]
func (this *Queries_MySpanner) Delete(ctx context.Context, db persist.SpannerRunnable) *Query_MySpanner_Delete {
return &Query_MySpanner_Delete{
opts: this.opts,
ctx: ctx,
db: db,
}
}
// Query_MySpanner_Delete (future doc string needed)
type Query_MySpanner_Delete struct {
opts Opts_MySpanner
db persist.SpannerRunnable
ctx context.Context
}
func (this *Query_MySpanner_Delete) QueryInType_ExampleTableRange() {}
func (this *Query_MySpanner_Delete) QueryOutType_Empty() {}
// Executes the query 'delete' with parameters retrieved from x.
// Fields used: [start_id end_id]
func (this *Query_MySpanner_Delete) Execute(x In_MySpanner_Delete) *Iter_MySpanner_Delete {
ctx := this.ctx
result := &Iter_MySpanner_Delete{
result: &SpannerResult{},
tm: this.opts.MAPPINGS,
ctx: ctx,
}
params, err := func() (map[string]interface{}, error) {
result := make(map[string]interface{})
result["start_id"] = x.GetStartId()
result["end_id"] = x.GetEndId()
return result, nil
}()
if err != nil {
result.err = err
return result
}
iter := this.db.QueryWithStats(ctx, spanner.Statement{
SQL: "DELETE FROM example_table START(@start_id) END(@end_id) KIND(CO)",
Params: params,
})
result.rows = iter
result.err = err
return result
}
// SelectAll returns a struct that will perform the 'select_all' query.
// When Execute is called, it will use the following fields:
// []
func (this *Queries_MySpanner) SelectAll(ctx context.Context, db persist.SpannerRunnable) *Query_MySpanner_SelectAll {
return &Query_MySpanner_SelectAll{
opts: this.opts,
ctx: ctx,
db: db,
}
}
// Query_MySpanner_SelectAll (future doc string needed)
type Query_MySpanner_SelectAll struct {
opts Opts_MySpanner
db persist.SpannerRunnable
ctx context.Context
}
func (this *Query_MySpanner_SelectAll) QueryInType_Empty() {}
func (this *Query_MySpanner_SelectAll) QueryOutType_ExampleTable() {}
// Executes the query 'select_all' with parameters retrieved from x.
// Fields used: []
func (this *Query_MySpanner_SelectAll) Execute(x In_MySpanner_SelectAll) *Iter_MySpanner_SelectAll {
ctx := this.ctx
result := &Iter_MySpanner_SelectAll{
result: &SpannerResult{},
tm: this.opts.MAPPINGS,
ctx: ctx,
}
params, err := func() (map[string]interface{}, error) {
result := make(map[string]interface{})
return result, nil
}()
if err != nil {
result.err = err
return result
}
iter := this.db.QueryWithStats(ctx, spanner.Statement{
SQL: "SELECT * FROM example_table",
Params: params,
})
result.rows = iter
result.err = err
return result
}
// Insert_3 returns a struct that will perform the 'insert_3' query.
// When Execute is called, it will use the following fields:
// [id start_time]
func (this *Queries_MySpanner) Insert_3(ctx context.Context, db persist.SpannerRunnable) *Query_MySpanner_Insert_3 {
return &Query_MySpanner_Insert_3{
opts: this.opts,
ctx: ctx,
db: db,
}
}
// Query_MySpanner_Insert_3 (future doc string needed)
type Query_MySpanner_Insert_3 struct {
opts Opts_MySpanner
db persist.SpannerRunnable
ctx context.Context
}
func (this *Query_MySpanner_Insert_3) QueryInType_ExampleTable() {}
func (this *Query_MySpanner_Insert_3) QueryOutType_Empty() {}
// Executes the query 'insert_3' with parameters retrieved from x.
// Fields used: [id start_time]
func (this *Query_MySpanner_Insert_3) Execute(x In_MySpanner_Insert_3) *Iter_MySpanner_Insert_3 {
ctx := this.ctx
result := &Iter_MySpanner_Insert_3{
result: &SpannerResult{},
tm: this.opts.MAPPINGS,
ctx: ctx,
}
params, err := func() (map[string]interface{}, error) {
result := make(map[string]interface{})
result["id"] = x.GetId()
start_time, err := proto.Marshal(x.GetStartTime())
if err != nil {
return nil, err
}
result["start_time"] = start_time
return result, nil
}()
if err != nil {
result.err = err
return result
}
iter := this.db.QueryWithStats(ctx, spanner.Statement{
SQL: "INSERT INTO example_table (id, start_time, name) VALUES (@id, @start_time, 3)",
Params: params,
})
result.rows = iter
result.err = err
return result
}
// DeleteId returns a struct that will perform the 'delete_id' query.
// When Execute is called, it will use the following fields:
// [id]
func (this *Queries_MySpanner) DeleteId(ctx context.Context, db persist.SpannerRunnable) *Query_MySpanner_DeleteId {
return &Query_MySpanner_DeleteId{
opts: this.opts,
ctx: ctx,
db: db,
}
}
// Query_MySpanner_DeleteId (future doc string needed)
type Query_MySpanner_DeleteId struct {
opts Opts_MySpanner
db persist.SpannerRunnable
ctx context.Context
}
func (this *Query_MySpanner_DeleteId) QueryInType_ExampleTable() {}
func (this *Query_MySpanner_DeleteId) QueryOutType_Empty() {}
// Executes the query 'delete_id' with parameters retrieved from x.
// Fields used: [id]
func (this *Query_MySpanner_DeleteId) Execute(x In_MySpanner_DeleteId) *Iter_MySpanner_DeleteId {
ctx := this.ctx
result := &Iter_MySpanner_DeleteId{
result: &SpannerResult{},
tm: this.opts.MAPPINGS,
ctx: ctx,
}
params, err := func() (map[string]interface{}, error) {
result := make(map[string]interface{})
result["id"] = x.GetId()
return result, nil
}()
if err != nil {
result.err = err
return result
}
iter := this.db.QueryWithStats(ctx, spanner.Statement{
SQL: "DELETE FROM example_table VALUES(@id)",
Params: params,
})
result.rows = iter
result.err = err
return result
}
// SetNameAsdf returns a struct that will perform the 'set_name_asdf' query.
// When Execute is called, it will use the following fields:
// [id]
func (this *Queries_MySpanner) SetNameAsdf(ctx context.Context, db persist.SpannerRunnable) *Query_MySpanner_SetNameAsdf {
return &Query_MySpanner_SetNameAsdf{
opts: this.opts,
ctx: ctx,
db: db,
}
}
// Query_MySpanner_SetNameAsdf (future doc string needed)
type Query_MySpanner_SetNameAsdf struct {
opts Opts_MySpanner
db persist.SpannerRunnable
ctx context.Context
}
func (this *Query_MySpanner_SetNameAsdf) QueryInType_ExampleTable() {}
func (this *Query_MySpanner_SetNameAsdf) QueryOutType_Empty() {}
// Executes the query 'set_name_asdf' with parameters retrieved from x.
// Fields used: [id]
func (this *Query_MySpanner_SetNameAsdf) Execute(x In_MySpanner_SetNameAsdf) *Iter_MySpanner_SetNameAsdf {
ctx := this.ctx
result := &Iter_MySpanner_SetNameAsdf{
result: &SpannerResult{},
tm: this.opts.MAPPINGS,
ctx: ctx,
}
params, err := func() (map[string]interface{}, error) {
result := make(map[string]interface{})
result["id"] = x.GetId()
return result, nil
}()
if err != nil {
result.err = err
return result
}
iter := this.db.QueryWithStats(ctx, spanner.Statement{
SQL: "update example_table set name='asdf' pk(id=@id)",
Params: params,
})
result.rows = iter
result.err = err
return result
}
type Iter_MySpanner_Insert struct {
result *SpannerResult
rows *spanner.RowIterator
err error
tm TypeMappings_MySpanner
ctx context.Context
}
func (this *Iter_MySpanner_Insert) IterOutTypeEmpty() {}
func (this *Iter_MySpanner_Insert) IterInTypeTestExampleTable() {}
// Each performs 'fun' on each row in the result set.
// Each respects the context passed to it.
// It will stop iteration, and returns this.ctx.Err() if encountered.
func (this *Iter_MySpanner_Insert) Each(fun func(*Row_MySpanner_Insert) error) error {
for {
select {
case <-this.ctx.Done():
return this.ctx.Err()
default:
if row, ok := this.Next(); !ok {
return nil
} else if err := fun(row); err != nil {
return err
}
}
}
}
// One returns the sole row, or ensures an error if there was not one result when this row is converted
func (this *Iter_MySpanner_Insert) One() *Row_MySpanner_Insert {
first, hasFirst := this.Next()
if first != nil && first.err != nil {
return &Row_MySpanner_Insert{err: first.err}
}
_, hasSecond := this.Next()
if !hasFirst || hasSecond {
amount := "none"
if hasSecond {
amount = "multiple"
}
return &Row_MySpanner_Insert{err: fmt.Errorf("expected exactly 1 result from query 'Insert' found %s", amount)}
}
return first
}
// Zero returns an error if there were any rows in the result
func (this *Iter_MySpanner_Insert) Zero() error {
row, ok := this.Next()
if row != nil && row.err != nil {
return row.err
}
if ok {
return fmt.Errorf("expected exactly 0 results from query 'Insert'")
}
return nil
}
// Next returns the next scanned row out of the database, or (nil, false) if there are no more rows
func (this *Iter_MySpanner_Insert) Next() (*Row_MySpanner_Insert, bool) {
row, err := this.rows.Next()
_ = row
if err == iterator.Done {
return nil, false
}
if err != nil {
return &Row_MySpanner_Insert{err: err}, true
}
res := &Empty{}
return &Row_MySpanner_Insert{item: res}, true
}
// Slice returns all rows found in the iterator as a Slice.
func (this *Iter_MySpanner_Insert) Slice() []*Row_MySpanner_Insert {
var results []*Row_MySpanner_Insert
for {
if i, ok := this.Next(); ok {
results = append(results, i)
} else {
break
}
}
return results
}
type Iter_MySpanner_Select struct {
result *SpannerResult
rows *spanner.RowIterator
err error
tm TypeMappings_MySpanner
ctx context.Context
}