/
entity.obx.go
2378 lines (2146 loc) · 86.4 KB
/
entity.obx.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
// Code generated by ObjectBox; DO NOT EDIT.
// Learn more about defining entities and generating this file - visit https://golang.objectbox.io/entity-annotations
package model
import (
"errors"
"github.com/google/flatbuffers/go"
"github.com/objectbox/objectbox-go/objectbox"
"github.com/objectbox/objectbox-go/objectbox/fbutils"
)
type entity_EntityInfo struct {
objectbox.Entity
Uid uint64
}
var EntityBinding = entity_EntityInfo{
Entity: objectbox.Entity{
Id: 1,
},
Uid: 3022148985475790732,
}
// Entity_ contains type-based Property helpers to facilitate some common operations such as Queries.
var Entity_ = struct {
Id *objectbox.PropertyUint64
Int *objectbox.PropertyInt
Int8 *objectbox.PropertyInt8
Int16 *objectbox.PropertyInt16
Int32 *objectbox.PropertyInt32
Int64 *objectbox.PropertyInt64
Uint *objectbox.PropertyUint
Uint8 *objectbox.PropertyUint8
Uint16 *objectbox.PropertyUint16
Uint32 *objectbox.PropertyUint32
Uint64 *objectbox.PropertyUint64
Bool *objectbox.PropertyBool
String *objectbox.PropertyString
Byte *objectbox.PropertyByte
ByteVector *objectbox.PropertyByteVector
Rune *objectbox.PropertyRune
Float32 *objectbox.PropertyFloat32
Float64 *objectbox.PropertyFloat64
Date *objectbox.PropertyInt64
Complex128 *objectbox.PropertyByteVector
StringVector *objectbox.PropertyStringVector
Related *objectbox.RelationToOne
RelatedPtr *objectbox.RelationToOne
RelatedPtr2 *objectbox.RelationToOne
IntPtr *objectbox.PropertyInt
Int8Ptr *objectbox.PropertyInt8
Int16Ptr *objectbox.PropertyInt16
Int32Ptr *objectbox.PropertyInt32
Int64Ptr *objectbox.PropertyInt64
UintPtr *objectbox.PropertyUint
Uint8Ptr *objectbox.PropertyUint8
Uint16Ptr *objectbox.PropertyUint16
Uint32Ptr *objectbox.PropertyUint32
Uint64Ptr *objectbox.PropertyUint64
BoolPtr *objectbox.PropertyBool
StringPtr *objectbox.PropertyString
BytePtr *objectbox.PropertyByte
RunePtr *objectbox.PropertyRune
Float32Ptr *objectbox.PropertyFloat32
Float64Ptr *objectbox.PropertyFloat64
StringVectorPtr *objectbox.PropertyStringVector
ByteVectorPtr *objectbox.PropertyByteVector
RelatedSlice *objectbox.RelationToMany
RelatedPtrSlice *objectbox.RelationToMany
}{
Id: &objectbox.PropertyUint64{
BaseProperty: &objectbox.BaseProperty{
Id: 1,
Entity: &EntityBinding.Entity,
},
},
Int: &objectbox.PropertyInt{
BaseProperty: &objectbox.BaseProperty{
Id: 2,
Entity: &EntityBinding.Entity,
},
},
Int8: &objectbox.PropertyInt8{
BaseProperty: &objectbox.BaseProperty{
Id: 3,
Entity: &EntityBinding.Entity,
},
},
Int16: &objectbox.PropertyInt16{
BaseProperty: &objectbox.BaseProperty{
Id: 4,
Entity: &EntityBinding.Entity,
},
},
Int32: &objectbox.PropertyInt32{
BaseProperty: &objectbox.BaseProperty{
Id: 5,
Entity: &EntityBinding.Entity,
},
},
Int64: &objectbox.PropertyInt64{
BaseProperty: &objectbox.BaseProperty{
Id: 6,
Entity: &EntityBinding.Entity,
},
},
Uint: &objectbox.PropertyUint{
BaseProperty: &objectbox.BaseProperty{
Id: 7,
Entity: &EntityBinding.Entity,
},
},
Uint8: &objectbox.PropertyUint8{
BaseProperty: &objectbox.BaseProperty{
Id: 8,
Entity: &EntityBinding.Entity,
},
},
Uint16: &objectbox.PropertyUint16{
BaseProperty: &objectbox.BaseProperty{
Id: 9,
Entity: &EntityBinding.Entity,
},
},
Uint32: &objectbox.PropertyUint32{
BaseProperty: &objectbox.BaseProperty{
Id: 10,
Entity: &EntityBinding.Entity,
},
},
Uint64: &objectbox.PropertyUint64{
BaseProperty: &objectbox.BaseProperty{
Id: 11,
Entity: &EntityBinding.Entity,
},
},
Bool: &objectbox.PropertyBool{
BaseProperty: &objectbox.BaseProperty{
Id: 12,
Entity: &EntityBinding.Entity,
},
},
String: &objectbox.PropertyString{
BaseProperty: &objectbox.BaseProperty{
Id: 13,
Entity: &EntityBinding.Entity,
},
},
Byte: &objectbox.PropertyByte{
BaseProperty: &objectbox.BaseProperty{
Id: 14,
Entity: &EntityBinding.Entity,
},
},
ByteVector: &objectbox.PropertyByteVector{
BaseProperty: &objectbox.BaseProperty{
Id: 15,
Entity: &EntityBinding.Entity,
},
},
Rune: &objectbox.PropertyRune{
BaseProperty: &objectbox.BaseProperty{
Id: 16,
Entity: &EntityBinding.Entity,
},
},
Float32: &objectbox.PropertyFloat32{
BaseProperty: &objectbox.BaseProperty{
Id: 17,
Entity: &EntityBinding.Entity,
},
},
Float64: &objectbox.PropertyFloat64{
BaseProperty: &objectbox.BaseProperty{
Id: 18,
Entity: &EntityBinding.Entity,
},
},
Date: &objectbox.PropertyInt64{
BaseProperty: &objectbox.BaseProperty{
Id: 19,
Entity: &EntityBinding.Entity,
},
},
Complex128: &objectbox.PropertyByteVector{
BaseProperty: &objectbox.BaseProperty{
Id: 20,
Entity: &EntityBinding.Entity,
},
},
StringVector: &objectbox.PropertyStringVector{
BaseProperty: &objectbox.BaseProperty{
Id: 21,
Entity: &EntityBinding.Entity,
},
},
Related: &objectbox.RelationToOne{
Property: &objectbox.BaseProperty{
Id: 22,
Entity: &EntityBinding.Entity,
},
Target: &TestEntityRelatedBinding.Entity,
},
RelatedPtr: &objectbox.RelationToOne{
Property: &objectbox.BaseProperty{
Id: 23,
Entity: &EntityBinding.Entity,
},
Target: &TestEntityRelatedBinding.Entity,
},
RelatedPtr2: &objectbox.RelationToOne{
Property: &objectbox.BaseProperty{
Id: 24,
Entity: &EntityBinding.Entity,
},
Target: &TestEntityRelatedBinding.Entity,
},
IntPtr: &objectbox.PropertyInt{
BaseProperty: &objectbox.BaseProperty{
Id: 25,
Entity: &EntityBinding.Entity,
},
},
Int8Ptr: &objectbox.PropertyInt8{
BaseProperty: &objectbox.BaseProperty{
Id: 26,
Entity: &EntityBinding.Entity,
},
},
Int16Ptr: &objectbox.PropertyInt16{
BaseProperty: &objectbox.BaseProperty{
Id: 27,
Entity: &EntityBinding.Entity,
},
},
Int32Ptr: &objectbox.PropertyInt32{
BaseProperty: &objectbox.BaseProperty{
Id: 28,
Entity: &EntityBinding.Entity,
},
},
Int64Ptr: &objectbox.PropertyInt64{
BaseProperty: &objectbox.BaseProperty{
Id: 29,
Entity: &EntityBinding.Entity,
},
},
UintPtr: &objectbox.PropertyUint{
BaseProperty: &objectbox.BaseProperty{
Id: 30,
Entity: &EntityBinding.Entity,
},
},
Uint8Ptr: &objectbox.PropertyUint8{
BaseProperty: &objectbox.BaseProperty{
Id: 31,
Entity: &EntityBinding.Entity,
},
},
Uint16Ptr: &objectbox.PropertyUint16{
BaseProperty: &objectbox.BaseProperty{
Id: 32,
Entity: &EntityBinding.Entity,
},
},
Uint32Ptr: &objectbox.PropertyUint32{
BaseProperty: &objectbox.BaseProperty{
Id: 33,
Entity: &EntityBinding.Entity,
},
},
Uint64Ptr: &objectbox.PropertyUint64{
BaseProperty: &objectbox.BaseProperty{
Id: 34,
Entity: &EntityBinding.Entity,
},
},
BoolPtr: &objectbox.PropertyBool{
BaseProperty: &objectbox.BaseProperty{
Id: 35,
Entity: &EntityBinding.Entity,
},
},
StringPtr: &objectbox.PropertyString{
BaseProperty: &objectbox.BaseProperty{
Id: 36,
Entity: &EntityBinding.Entity,
},
},
BytePtr: &objectbox.PropertyByte{
BaseProperty: &objectbox.BaseProperty{
Id: 38,
Entity: &EntityBinding.Entity,
},
},
RunePtr: &objectbox.PropertyRune{
BaseProperty: &objectbox.BaseProperty{
Id: 40,
Entity: &EntityBinding.Entity,
},
},
Float32Ptr: &objectbox.PropertyFloat32{
BaseProperty: &objectbox.BaseProperty{
Id: 41,
Entity: &EntityBinding.Entity,
},
},
Float64Ptr: &objectbox.PropertyFloat64{
BaseProperty: &objectbox.BaseProperty{
Id: 42,
Entity: &EntityBinding.Entity,
},
},
StringVectorPtr: &objectbox.PropertyStringVector{
BaseProperty: &objectbox.BaseProperty{
Id: 43,
Entity: &EntityBinding.Entity,
},
},
ByteVectorPtr: &objectbox.PropertyByteVector{
BaseProperty: &objectbox.BaseProperty{
Id: 44,
Entity: &EntityBinding.Entity,
},
},
RelatedSlice: &objectbox.RelationToMany{
Id: 4,
Source: &EntityBinding.Entity,
Target: &EntityByValueBinding.Entity,
},
RelatedPtrSlice: &objectbox.RelationToMany{
Id: 5,
Source: &EntityBinding.Entity,
Target: &TestEntityRelatedBinding.Entity,
},
}
// GeneratorVersion is called by ObjectBox to verify the compatibility of the generator used to generate this code
func (entity_EntityInfo) GeneratorVersion() int {
return 6
}
// AddToModel is called by ObjectBox during model build
func (entity_EntityInfo) AddToModel(model *objectbox.Model) {
model.Entity("Entity", 1, 3022148985475790732)
model.Property("Id", 6, 1, 1213346202559552829)
model.PropertyFlags(1)
model.Property("Int", 6, 2, 6609825840127351046)
model.Property("Int8", 2, 3, 741904540265547276)
model.Property("Int16", 3, 4, 2102961483425256790)
model.Property("Int32", 5, 5, 5086065890743931723)
model.Property("Int64", 6, 6, 7993850425898343586)
model.Property("Uint", 6, 7, 993618338451248101)
model.PropertyFlags(8192)
model.Property("Uint8", 2, 8, 8794162191867215541)
model.PropertyFlags(8192)
model.Property("Uint16", 3, 9, 8820932096807845950)
model.PropertyFlags(8192)
model.Property("Uint32", 5, 10, 6060435196424462358)
model.PropertyFlags(8192)
model.Property("Uint64", 6, 11, 6159011311237949479)
model.PropertyFlags(8192)
model.Property("Bool", 1, 12, 13717766026420552)
model.Property("String", 9, 13, 3525810560076343996)
model.Property("Byte", 2, 14, 4035373893984224671)
model.PropertyFlags(8192)
model.Property("ByteVector", 23, 15, 1294888641203478533)
model.Property("Rune", 5, 16, 445652208596094853)
model.Property("Float32", 7, 17, 2321055489159952634)
model.Property("Float64", 8, 18, 681625187526498317)
model.Property("Date", 10, 19, 2927532418453906842)
model.Property("Complex128", 23, 20, 2323084480359838337)
model.Property("StringVector", 30, 21, 3893192683529392073)
model.Property("Related", 11, 22, 6981354105569415135)
model.PropertyFlags(520)
model.PropertyRelation("TestEntityRelated", 1, 7297830522090799401)
model.Property("RelatedPtr", 11, 23, 2938782103279095882)
model.PropertyFlags(520)
model.PropertyRelation("TestEntityRelated", 2, 1636618737379039866)
model.Property("RelatedPtr2", 11, 24, 7776035803207726954)
model.PropertyFlags(520)
model.PropertyRelation("TestEntityRelated", 3, 6077259218141868916)
model.Property("IntPtr", 6, 25, 373339162565757738)
model.Property("Int8Ptr", 2, 26, 4408376776468442700)
model.Property("Int16Ptr", 3, 27, 7767638672655087796)
model.Property("Int32Ptr", 5, 28, 4484862171635994061)
model.Property("Int64Ptr", 6, 29, 5702162443518573921)
model.Property("UintPtr", 6, 30, 1419849538019864166)
model.PropertyFlags(8192)
model.Property("Uint8Ptr", 2, 31, 5666684665126533193)
model.PropertyFlags(8192)
model.Property("Uint16Ptr", 3, 32, 588273992483456755)
model.PropertyFlags(8192)
model.Property("Uint32Ptr", 5, 33, 1921936640604795696)
model.PropertyFlags(8192)
model.Property("Uint64Ptr", 6, 34, 508303024901376893)
model.PropertyFlags(8192)
model.Property("BoolPtr", 1, 35, 8481118512070824875)
model.Property("StringPtr", 9, 36, 8409889434685629914)
model.Property("BytePtr", 2, 38, 7395768407310126147)
model.PropertyFlags(8192)
model.Property("RunePtr", 5, 40, 5826738612842297282)
model.Property("Float32Ptr", 7, 41, 8081176555310747578)
model.Property("Float64Ptr", 8, 42, 9203830121246076395)
model.Property("StringVectorPtr", 30, 43, 4222000762705400780)
model.Property("ByteVectorPtr", 23, 44, 6100401720382402484)
model.EntityLastPropertyId(44, 6100401720382402484)
model.Relation(4, 5379891792880176678, EntityByValueBinding.Id, EntityByValueBinding.Uid)
model.Relation(5, 1694321226239708534, TestEntityRelatedBinding.Id, TestEntityRelatedBinding.Uid)
}
// GetId is called by ObjectBox during Put operations to check for existing ID on an object
func (entity_EntityInfo) GetId(object interface{}) (uint64, error) {
return object.(*Entity).Id, nil
}
// SetId is called by ObjectBox during Put to update an ID on an object that has just been inserted
func (entity_EntityInfo) SetId(object interface{}, id uint64) error {
object.(*Entity).Id = id
return nil
}
// PutRelated is called by ObjectBox to put related entities before the object itself is flattened and put
func (entity_EntityInfo) PutRelated(ob *objectbox.ObjectBox, object interface{}, id uint64) error {
if rel := &object.(*Entity).Related; rel != nil {
if rId, err := TestEntityRelatedBinding.GetId(rel); err != nil {
return err
} else if rId == 0 {
// NOTE Put/PutAsync() has a side-effect of setting the rel.ID
if _, err := BoxForTestEntityRelated(ob).Put(rel); err != nil {
return err
}
}
}
if rel := object.(*Entity).RelatedPtr; rel != nil {
if rId, err := TestEntityRelatedBinding.GetId(rel); err != nil {
return err
} else if rId == 0 {
// NOTE Put/PutAsync() has a side-effect of setting the rel.ID
if _, err := BoxForTestEntityRelated(ob).Put(rel); err != nil {
return err
}
}
}
if rel := object.(*Entity).RelatedPtr2; rel != nil {
if rId, err := TestEntityRelatedBinding.GetId(rel); err != nil {
return err
} else if rId == 0 {
// NOTE Put/PutAsync() has a side-effect of setting the rel.ID
if _, err := BoxForTestEntityRelated(ob).Put(rel); err != nil {
return err
}
}
}
if err := BoxForEntity(ob).RelationReplace(Entity_.RelatedSlice, id, object, object.(*Entity).RelatedSlice); err != nil {
return err
}
if object.(*Entity).RelatedPtrSlice != nil { // lazy-loaded relations without EntityBox::FetchRelatedPtrSlice() called are nil
if err := BoxForEntity(ob).RelationReplace(Entity_.RelatedPtrSlice, id, object, object.(*Entity).RelatedPtrSlice); err != nil {
return err
}
}
return nil
}
// Flatten is called by ObjectBox to transform an object to a FlatBuffer
func (entity_EntityInfo) Flatten(object interface{}, fbb *flatbuffers.Builder, id uint64) error {
obj := object.(*Entity)
var propDate int64
{
var err error
propDate, err = objectbox.TimeInt64ConvertToDatabaseValue(obj.Date)
if err != nil {
return errors.New("converter objectbox.TimeInt64ConvertToDatabaseValue() failed on Entity.Date: " + err.Error())
}
}
var propComplex128 []byte
{
var err error
propComplex128, err = complex128BytesToDatabaseValue(obj.Complex128)
if err != nil {
return errors.New("converter complex128BytesToDatabaseValue() failed on Entity.Complex128: " + err.Error())
}
}
var offsetString = fbutils.CreateStringOffset(fbb, obj.String)
var offsetByteVector = fbutils.CreateByteVectorOffset(fbb, obj.ByteVector)
var offsetComplex128 = fbutils.CreateByteVectorOffset(fbb, propComplex128)
var offsetStringVector = fbutils.CreateStringVectorOffset(fbb, obj.StringVector)
var offsetStringPtr flatbuffers.UOffsetT
if obj.StringPtr != nil {
offsetStringPtr = fbutils.CreateStringOffset(fbb, *obj.StringPtr)
}
var offsetStringVectorPtr flatbuffers.UOffsetT
if obj.StringVectorPtr != nil {
offsetStringVectorPtr = fbutils.CreateStringVectorOffset(fbb, *obj.StringVectorPtr)
}
var offsetByteVectorPtr flatbuffers.UOffsetT
if obj.ByteVectorPtr != nil {
offsetByteVectorPtr = fbutils.CreateByteVectorOffset(fbb, *obj.ByteVectorPtr)
}
var rIdRelated uint64
if rel := &obj.Related; rel != nil {
if rId, err := TestEntityRelatedBinding.GetId(rel); err != nil {
return err
} else {
rIdRelated = rId
}
}
var rIdRelatedPtr uint64
if rel := obj.RelatedPtr; rel != nil {
if rId, err := TestEntityRelatedBinding.GetId(rel); err != nil {
return err
} else {
rIdRelatedPtr = rId
}
}
var rIdRelatedPtr2 uint64
if rel := obj.RelatedPtr2; rel != nil {
if rId, err := TestEntityRelatedBinding.GetId(rel); err != nil {
return err
} else {
rIdRelatedPtr2 = rId
}
}
// build the FlatBuffers object
fbb.StartObject(44)
fbutils.SetUint64Slot(fbb, 0, id)
fbutils.SetInt64Slot(fbb, 1, int64(obj.Int))
fbutils.SetInt8Slot(fbb, 2, obj.Int8)
fbutils.SetInt16Slot(fbb, 3, obj.Int16)
fbutils.SetInt32Slot(fbb, 4, obj.Int32)
fbutils.SetInt64Slot(fbb, 5, obj.Int64)
fbutils.SetUint64Slot(fbb, 6, uint64(obj.Uint))
fbutils.SetUint8Slot(fbb, 7, obj.Uint8)
fbutils.SetUint16Slot(fbb, 8, obj.Uint16)
fbutils.SetUint32Slot(fbb, 9, obj.Uint32)
fbutils.SetUint64Slot(fbb, 10, obj.Uint64)
fbutils.SetBoolSlot(fbb, 11, obj.Bool)
fbutils.SetUOffsetTSlot(fbb, 12, offsetString)
fbutils.SetUOffsetTSlot(fbb, 20, offsetStringVector)
fbutils.SetUint8Slot(fbb, 13, obj.Byte)
fbutils.SetUOffsetTSlot(fbb, 14, offsetByteVector)
fbutils.SetInt32Slot(fbb, 15, obj.Rune)
fbutils.SetFloat32Slot(fbb, 16, obj.Float32)
fbutils.SetFloat64Slot(fbb, 17, obj.Float64)
fbutils.SetInt64Slot(fbb, 18, propDate)
fbutils.SetUOffsetTSlot(fbb, 19, offsetComplex128)
fbutils.SetUint64Slot(fbb, 21, rIdRelated)
if obj.RelatedPtr != nil {
fbutils.SetUint64Slot(fbb, 22, rIdRelatedPtr)
}
if obj.RelatedPtr2 != nil {
fbutils.SetUint64Slot(fbb, 23, rIdRelatedPtr2)
}
if obj.IntPtr != nil {
fbutils.SetInt64Slot(fbb, 24, int64(*obj.IntPtr))
}
if obj.Int8Ptr != nil {
fbutils.SetInt8Slot(fbb, 25, *obj.Int8Ptr)
}
if obj.Int16Ptr != nil {
fbutils.SetInt16Slot(fbb, 26, *obj.Int16Ptr)
}
if obj.Int32Ptr != nil {
fbutils.SetInt32Slot(fbb, 27, *obj.Int32Ptr)
}
if obj.Int64Ptr != nil {
fbutils.SetInt64Slot(fbb, 28, *obj.Int64Ptr)
}
if obj.UintPtr != nil {
fbutils.SetUint64Slot(fbb, 29, uint64(*obj.UintPtr))
}
if obj.Uint8Ptr != nil {
fbutils.SetUint8Slot(fbb, 30, *obj.Uint8Ptr)
}
if obj.Uint16Ptr != nil {
fbutils.SetUint16Slot(fbb, 31, *obj.Uint16Ptr)
}
if obj.Uint32Ptr != nil {
fbutils.SetUint32Slot(fbb, 32, *obj.Uint32Ptr)
}
if obj.Uint64Ptr != nil {
fbutils.SetUint64Slot(fbb, 33, *obj.Uint64Ptr)
}
if obj.BoolPtr != nil {
fbutils.SetBoolSlot(fbb, 34, *obj.BoolPtr)
}
if obj.StringPtr != nil {
fbutils.SetUOffsetTSlot(fbb, 35, offsetStringPtr)
}
if obj.StringVectorPtr != nil {
fbutils.SetUOffsetTSlot(fbb, 42, offsetStringVectorPtr)
}
if obj.BytePtr != nil {
fbutils.SetUint8Slot(fbb, 37, *obj.BytePtr)
}
if obj.ByteVectorPtr != nil {
fbutils.SetUOffsetTSlot(fbb, 43, offsetByteVectorPtr)
}
if obj.RunePtr != nil {
fbutils.SetInt32Slot(fbb, 39, *obj.RunePtr)
}
if obj.Float32Ptr != nil {
fbutils.SetFloat32Slot(fbb, 40, *obj.Float32Ptr)
}
if obj.Float64Ptr != nil {
fbutils.SetFloat64Slot(fbb, 41, *obj.Float64Ptr)
}
return nil
}
// Load is called by ObjectBox to load an object from a FlatBuffer
func (entity_EntityInfo) Load(ob *objectbox.ObjectBox, bytes []byte) (interface{}, error) {
if len(bytes) == 0 { // sanity check, should "never" happen
return nil, errors.New("can't deserialize an object of type 'Entity' - no data received")
}
var table = &flatbuffers.Table{
Bytes: bytes,
Pos: flatbuffers.GetUOffsetT(bytes),
}
var propId = table.GetUint64Slot(4, 0)
propDate, err := objectbox.TimeInt64ConvertToEntityProperty(fbutils.GetInt64Slot(table, 40))
if err != nil {
return nil, errors.New("converter objectbox.TimeInt64ConvertToEntityProperty() failed on Entity.Date: " + err.Error())
}
propComplex128, err := complex128BytesToEntityProperty(fbutils.GetByteVectorSlot(table, 42))
if err != nil {
return nil, errors.New("converter complex128BytesToEntityProperty() failed on Entity.Complex128: " + err.Error())
}
var relRelated *TestEntityRelated
if rId := fbutils.GetUint64Slot(table, 46); rId > 0 {
if rObject, err := BoxForTestEntityRelated(ob).Get(rId); err != nil {
return nil, err
} else if rObject == nil {
relRelated = &TestEntityRelated{}
} else {
relRelated = rObject
}
} else {
relRelated = &TestEntityRelated{}
}
var relRelatedPtr *TestEntityRelated
if rId := fbutils.GetUint64PtrSlot(table, 48); rId != nil && *rId > 0 {
if rObject, err := BoxForTestEntityRelated(ob).Get(*rId); err != nil {
return nil, err
} else {
relRelatedPtr = rObject
}
}
var relRelatedPtr2 *TestEntityRelated
if rId := fbutils.GetUint64PtrSlot(table, 50); rId != nil && *rId > 0 {
if rObject, err := BoxForTestEntityRelated(ob).Get(*rId); err != nil {
return nil, err
} else {
relRelatedPtr2 = rObject
}
}
var relRelatedSlice []EntityByValue
if rIds, err := BoxForEntity(ob).RelationIds(Entity_.RelatedSlice, propId); err != nil {
return nil, err
} else if rSlice, err := BoxForEntityByValue(ob).GetManyExisting(rIds...); err != nil {
return nil, err
} else {
relRelatedSlice = rSlice
}
return &Entity{
Id: propId,
Int: fbutils.GetIntSlot(table, 6),
Int8: fbutils.GetInt8Slot(table, 8),
Int16: fbutils.GetInt16Slot(table, 10),
Int32: fbutils.GetInt32Slot(table, 12),
Int64: fbutils.GetInt64Slot(table, 14),
Uint: fbutils.GetUintSlot(table, 16),
Uint8: fbutils.GetUint8Slot(table, 18),
Uint16: fbutils.GetUint16Slot(table, 20),
Uint32: fbutils.GetUint32Slot(table, 22),
Uint64: fbutils.GetUint64Slot(table, 24),
Bool: fbutils.GetBoolSlot(table, 26),
String: fbutils.GetStringSlot(table, 28),
StringVector: fbutils.GetStringVectorSlot(table, 44),
Byte: fbutils.GetByteSlot(table, 30),
ByteVector: fbutils.GetByteVectorSlot(table, 32),
Rune: fbutils.GetRuneSlot(table, 34),
Float32: fbutils.GetFloat32Slot(table, 36),
Float64: fbutils.GetFloat64Slot(table, 38),
Date: propDate,
Complex128: propComplex128,
Related: *relRelated,
RelatedPtr: relRelatedPtr,
RelatedPtr2: relRelatedPtr2,
RelatedSlice: relRelatedSlice,
RelatedPtrSlice: nil, // use EntityBox::FetchRelatedPtrSlice() to fetch this lazy-loaded relation,
IntPtr: fbutils.GetIntPtrSlot(table, 52),
Int8Ptr: fbutils.GetInt8PtrSlot(table, 54),
Int16Ptr: fbutils.GetInt16PtrSlot(table, 56),
Int32Ptr: fbutils.GetInt32PtrSlot(table, 58),
Int64Ptr: fbutils.GetInt64PtrSlot(table, 60),
UintPtr: fbutils.GetUintPtrSlot(table, 62),
Uint8Ptr: fbutils.GetUint8PtrSlot(table, 64),
Uint16Ptr: fbutils.GetUint16PtrSlot(table, 66),
Uint32Ptr: fbutils.GetUint32PtrSlot(table, 68),
Uint64Ptr: fbutils.GetUint64PtrSlot(table, 70),
BoolPtr: fbutils.GetBoolPtrSlot(table, 72),
StringPtr: fbutils.GetStringPtrSlot(table, 74),
StringVectorPtr: fbutils.GetStringVectorPtrSlot(table, 88),
BytePtr: fbutils.GetBytePtrSlot(table, 78),
ByteVectorPtr: fbutils.GetByteVectorPtrSlot(table, 90),
RunePtr: fbutils.GetRunePtrSlot(table, 82),
Float32Ptr: fbutils.GetFloat32PtrSlot(table, 84),
Float64Ptr: fbutils.GetFloat64PtrSlot(table, 86),
}, nil
}
// MakeSlice is called by ObjectBox to construct a new slice to hold the read objects
func (entity_EntityInfo) MakeSlice(capacity int) interface{} {
return make([]*Entity, 0, capacity)
}
// AppendToSlice is called by ObjectBox to fill the slice of the read objects
func (entity_EntityInfo) AppendToSlice(slice interface{}, object interface{}) interface{} {
if object == nil {
return append(slice.([]*Entity), nil)
}
return append(slice.([]*Entity), object.(*Entity))
}
// Box provides CRUD access to Entity objects
type EntityBox struct {
*objectbox.Box
}
// BoxForEntity opens a box of Entity objects
func BoxForEntity(ob *objectbox.ObjectBox) *EntityBox {
return &EntityBox{
Box: ob.InternalBox(1),
}
}
// Put synchronously inserts/updates a single object.
// In case the Id is not specified, it would be assigned automatically (auto-increment).
// When inserting, the Entity.Id property on the passed object will be assigned the new ID as well.
func (box *EntityBox) Put(object *Entity) (uint64, error) {
return box.Box.Put(object)
}
// Insert synchronously inserts a single object. As opposed to Put, Insert will fail if given an ID that already exists.
// In case the Id is not specified, it would be assigned automatically (auto-increment).
// When inserting, the Entity.Id property on the passed object will be assigned the new ID as well.
func (box *EntityBox) Insert(object *Entity) (uint64, error) {
return box.Box.Insert(object)
}
// Update synchronously updates a single object.
// As opposed to Put, Update will fail if an object with the same ID is not found in the database.
func (box *EntityBox) Update(object *Entity) error {
return box.Box.Update(object)
}
// PutAsync asynchronously inserts/updates a single object.
// Deprecated: use box.Async().Put() instead
func (box *EntityBox) PutAsync(object *Entity) (uint64, error) {
return box.Box.PutAsync(object)
}
// PutMany inserts multiple objects in single transaction.
// In case Ids are not set on the objects, they would be assigned automatically (auto-increment).
//
// Returns: IDs of the put objects (in the same order).
// When inserting, the Entity.Id property on the objects in the slice will be assigned the new IDs as well.
//
// Note: In case an error occurs during the transaction, some of the objects may already have the Entity.Id assigned
// even though the transaction has been rolled back and the objects are not stored under those IDs.
//
// Note: The slice may be empty or even nil; in both cases, an empty IDs slice and no error is returned.
func (box *EntityBox) PutMany(objects []*Entity) ([]uint64, error) {
return box.Box.PutMany(objects)
}
// Get reads a single object.
//
// Returns nil (and no error) in case the object with the given ID doesn't exist.
func (box *EntityBox) Get(id uint64) (*Entity, error) {
object, err := box.Box.Get(id)
if err != nil {
return nil, err
} else if object == nil {
return nil, nil
}
return object.(*Entity), nil
}
// GetMany reads multiple objects at once.
// If any of the objects doesn't exist, its position in the return slice is nil
func (box *EntityBox) GetMany(ids ...uint64) ([]*Entity, error) {
objects, err := box.Box.GetMany(ids...)
if err != nil {
return nil, err
}
return objects.([]*Entity), nil
}
// GetManyExisting reads multiple objects at once, skipping those that do not exist.
func (box *EntityBox) GetManyExisting(ids ...uint64) ([]*Entity, error) {
objects, err := box.Box.GetManyExisting(ids...)
if err != nil {
return nil, err
}
return objects.([]*Entity), nil
}
// GetAll reads all stored objects
func (box *EntityBox) GetAll() ([]*Entity, error) {
objects, err := box.Box.GetAll()
if err != nil {
return nil, err
}
return objects.([]*Entity), nil
}
// FetchRelatedPtrSlice reads target objects for relation Entity::RelatedPtrSlice.
// It will "GetManyExisting()" all related TestEntityRelated objects for each source object
// and set sourceObject.RelatedPtrSlice to the slice of related objects, as currently stored in DB.
func (box *EntityBox) FetchRelatedPtrSlice(sourceObjects ...*Entity) error {
var slices = make([][]*TestEntityRelated, len(sourceObjects))
err := box.ObjectBox.RunInReadTx(func() error {
// collect slices before setting the source objects' fields
// this keeps all the sourceObjects untouched in case there's an error during any of the requests
for k, object := range sourceObjects {
rIds, err := box.RelationIds(Entity_.RelatedPtrSlice, object.Id)
if err == nil {
slices[k], err = BoxForTestEntityRelated(box.ObjectBox).GetManyExisting(rIds...)
}
if err != nil {
return err
}
}
return nil
})
if err == nil { // update the field on all objects if we got all slices
for k := range sourceObjects {
sourceObjects[k].RelatedPtrSlice = slices[k]
}
}
return err
}
// Remove deletes a single object
func (box *EntityBox) Remove(object *Entity) error {
return box.Box.Remove(object)
}
// RemoveMany deletes multiple objects at once.
// Returns the number of deleted object or error on failure.
// Note that this method will not fail if an object is not found (e.g. already removed).
// In case you need to strictly check whether all of the objects exist before removing them,
// you can execute multiple box.Contains() and box.Remove() inside a single write transaction.
func (box *EntityBox) RemoveMany(objects ...*Entity) (uint64, error) {
var ids = make([]uint64, len(objects))
for k, object := range objects {
ids[k] = object.Id
}
return box.Box.RemoveIds(ids...)
}
// Creates a query with the given conditions. Use the fields of the Entity_ struct to create conditions.
// Keep the *EntityQuery if you intend to execute the query multiple times.
// Note: this function panics if you try to create illegal queries; e.g. use properties of an alien type.
// This is typically a programming error. Use QueryOrError instead if you want the explicit error check.
func (box *EntityBox) Query(conditions ...objectbox.Condition) *EntityQuery {
return &EntityQuery{
box.Box.Query(conditions...),
}
}
// Creates a query with the given conditions. Use the fields of the Entity_ struct to create conditions.
// Keep the *EntityQuery if you intend to execute the query multiple times.
func (box *EntityBox) QueryOrError(conditions ...objectbox.Condition) (*EntityQuery, error) {
if query, err := box.Box.QueryOrError(conditions...); err != nil {
return nil, err
} else {
return &EntityQuery{query}, nil
}
}
// Async provides access to the default Async Box for asynchronous operations. See EntityAsyncBox for more information.
func (box *EntityBox) Async() *EntityAsyncBox {
return &EntityAsyncBox{AsyncBox: box.Box.Async()}
}
// EntityAsyncBox provides asynchronous operations on Entity objects.
//
// Asynchronous operations are executed on a separate internal thread for better performance.
//
// There are two main use cases:
//
// 1) "execute & forget:" you gain faster put/remove operations as you don't have to wait for the transaction to finish.
//
// 2) Many small transactions: if your write load is typically a lot of individual puts that happen in parallel,
// this will merge small transactions into bigger ones. This results in a significant gain in overall throughput.
//
// In situations with (extremely) high async load, an async method may be throttled (~1ms) or delayed up to 1 second.
// In the unlikely event that the object could still not be enqueued (full queue), an error will be returned.
//
// Note that async methods do not give you hard durability guarantees like the synchronous Box provides.
// There is a small time window in which the data may not have been committed durably yet.
type EntityAsyncBox struct {
*objectbox.AsyncBox
}
// AsyncBoxForEntity creates a new async box with the given operation timeout in case an async queue is full.
// The returned struct must be freed explicitly using the Close() method.
// It's usually preferable to use EntityBox::Async() which takes care of resource management and doesn't require closing.
func AsyncBoxForEntity(ob *objectbox.ObjectBox, timeoutMs uint64) *EntityAsyncBox {
var async, err = objectbox.NewAsyncBox(ob, 1, timeoutMs)
if err != nil {
panic("Could not create async box for entity ID 1: %s" + err.Error())
}
return &EntityAsyncBox{AsyncBox: async}
}
// Put inserts/updates a single object asynchronously.
// When inserting a new object, the Id property on the passed object will be assigned the new ID the entity would hold
// if the insert is ultimately successful. The newly assigned ID may not become valid if the insert fails.
func (asyncBox *EntityAsyncBox) Put(object *Entity) (uint64, error) {
return asyncBox.AsyncBox.Put(object)
}
// Insert a single object asynchronously.
// The Id property on the passed object will be assigned the new ID the entity would hold if the insert is ultimately
// successful. The newly assigned ID may not become valid if the insert fails.
// Fails silently if an object with the same ID already exists (this error is not returned).
func (asyncBox *EntityAsyncBox) Insert(object *Entity) (id uint64, err error) {
return asyncBox.AsyncBox.Insert(object)
}
// Update a single object asynchronously.
// The object must already exists or the update fails silently (without an error returned).
func (asyncBox *EntityAsyncBox) Update(object *Entity) error {
return asyncBox.AsyncBox.Update(object)
}
// Remove deletes a single object asynchronously.
func (asyncBox *EntityAsyncBox) Remove(object *Entity) error {
return asyncBox.AsyncBox.Remove(object)
}
// Query provides a way to search stored objects
//
// For example, you can find all Entity which Id is either 42 or 47:
// box.Query(Entity_.Id.In(42, 47)).Find()
type EntityQuery struct {
*objectbox.Query
}
// Find returns all objects matching the query
func (query *EntityQuery) Find() ([]*Entity, error) {
objects, err := query.Query.Find()
if err != nil {
return nil, err
}
return objects.([]*Entity), nil
}
// Offset defines the index of the first object to process (how many objects to skip)
func (query *EntityQuery) Offset(offset uint64) *EntityQuery {
query.Query.Offset(offset)
return query
}
// Limit sets the number of elements to process by the query
func (query *EntityQuery) Limit(limit uint64) *EntityQuery {
query.Query.Limit(limit)
return query
}
type testStringIdEntity_EntityInfo struct {
objectbox.Entity
Uid uint64
}