-
Notifications
You must be signed in to change notification settings - Fork 0
/
gong.go
1889 lines (1689 loc) · 55.9 KB
/
gong.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
// generated code - do not edit
package models
import (
"cmp"
"errors"
"fmt"
"math"
"slices"
"time"
"golang.org/x/exp/maps"
)
func __Gong__Abs(x int) int {
if x < 0 {
return -x
}
return x
}
// errUnkownEnum is returns when a value cannot match enum values
var errUnkownEnum = errors.New("unkown enum")
// needed to avoid when fmt package is not needed by generated code
var __dummy__fmt_variable fmt.Scanner
// idem for math package when not need by generated code
var __dummy_math_variable = math.E
// swagger:ignore
type __void any
// needed for creating set of instances in the stage
var __member __void
// GongStructInterface is the interface met by GongStructs
// It allows runtime reflexion of instances (without the hassle of the "reflect" package)
type GongStructInterface interface {
GetName() (res string)
// GetID() (res int)
// GetFields() (res []string)
// GetFieldStringValue(fieldName string) (res string)
}
// StageStruct enables storage of staged instances
// swagger:ignore
type StageStruct struct {
path string
// insertion point for definition of arrays registering instances
Astructs map[*Astruct]any
Astructs_mapString map[string]*Astruct
// insertion point for slice of pointers maps
Astruct_Anarrayofb_reverseMap map[*Bstruct]*Astruct
Astruct_Anarrayofa_reverseMap map[*Astruct]*Astruct
Astruct_Anotherarrayofb_reverseMap map[*Bstruct]*Astruct
Astruct_AnarrayofbUse_reverseMap map[*AstructBstructUse]*Astruct
Astruct_Anarrayofb2Use_reverseMap map[*AstructBstruct2Use]*Astruct
OnAfterAstructCreateCallback OnAfterCreateInterface[Astruct]
OnAfterAstructUpdateCallback OnAfterUpdateInterface[Astruct]
OnAfterAstructDeleteCallback OnAfterDeleteInterface[Astruct]
OnAfterAstructReadCallback OnAfterReadInterface[Astruct]
AstructBstruct2Uses map[*AstructBstruct2Use]any
AstructBstruct2Uses_mapString map[string]*AstructBstruct2Use
// insertion point for slice of pointers maps
OnAfterAstructBstruct2UseCreateCallback OnAfterCreateInterface[AstructBstruct2Use]
OnAfterAstructBstruct2UseUpdateCallback OnAfterUpdateInterface[AstructBstruct2Use]
OnAfterAstructBstruct2UseDeleteCallback OnAfterDeleteInterface[AstructBstruct2Use]
OnAfterAstructBstruct2UseReadCallback OnAfterReadInterface[AstructBstruct2Use]
AstructBstructUses map[*AstructBstructUse]any
AstructBstructUses_mapString map[string]*AstructBstructUse
// insertion point for slice of pointers maps
OnAfterAstructBstructUseCreateCallback OnAfterCreateInterface[AstructBstructUse]
OnAfterAstructBstructUseUpdateCallback OnAfterUpdateInterface[AstructBstructUse]
OnAfterAstructBstructUseDeleteCallback OnAfterDeleteInterface[AstructBstructUse]
OnAfterAstructBstructUseReadCallback OnAfterReadInterface[AstructBstructUse]
Bstructs map[*Bstruct]any
Bstructs_mapString map[string]*Bstruct
// insertion point for slice of pointers maps
OnAfterBstructCreateCallback OnAfterCreateInterface[Bstruct]
OnAfterBstructUpdateCallback OnAfterUpdateInterface[Bstruct]
OnAfterBstructDeleteCallback OnAfterDeleteInterface[Bstruct]
OnAfterBstructReadCallback OnAfterReadInterface[Bstruct]
Dstructs map[*Dstruct]any
Dstructs_mapString map[string]*Dstruct
// insertion point for slice of pointers maps
Dstruct_Anarrayofb_reverseMap map[*Bstruct]*Dstruct
OnAfterDstructCreateCallback OnAfterCreateInterface[Dstruct]
OnAfterDstructUpdateCallback OnAfterUpdateInterface[Dstruct]
OnAfterDstructDeleteCallback OnAfterDeleteInterface[Dstruct]
OnAfterDstructReadCallback OnAfterReadInterface[Dstruct]
Fstructs map[*Fstruct]any
Fstructs_mapString map[string]*Fstruct
// insertion point for slice of pointers maps
OnAfterFstructCreateCallback OnAfterCreateInterface[Fstruct]
OnAfterFstructUpdateCallback OnAfterUpdateInterface[Fstruct]
OnAfterFstructDeleteCallback OnAfterDeleteInterface[Fstruct]
OnAfterFstructReadCallback OnAfterReadInterface[Fstruct]
AllModelsStructCreateCallback AllModelsStructCreateInterface
AllModelsStructDeleteCallback AllModelsStructDeleteInterface
BackRepo BackRepoInterface
// if set will be called before each commit to the back repo
OnInitCommitCallback OnInitCommitInterface
OnInitCommitFromFrontCallback OnInitCommitInterface
OnInitCommitFromBackCallback OnInitCommitInterface
// store the number of instance per gongstruct
Map_GongStructName_InstancesNb map[string]int
// store meta package import
MetaPackageImportPath string
MetaPackageImportAlias string
// to be removed after fix of [issue](https://github.com/golang/go/issues/57559)
// map to enable docLink renaming when an identifier is renamed
Map_DocLink_Renaming map[string]GONG__Identifier
// the to be removed stops here
}
func (stage *StageStruct) GetType() string {
return "github.com/fullstack-lang/gong/test/go/models"
}
type GONG__Identifier struct {
Ident string
Type GONG__ExpressionType
}
type OnInitCommitInterface interface {
BeforeCommit(stage *StageStruct)
}
// OnAfterCreateInterface callback when an instance is updated from the front
type OnAfterCreateInterface[Type Gongstruct] interface {
OnAfterCreate(stage *StageStruct,
instance *Type)
}
// OnAfterReadInterface callback when an instance is updated from the front
type OnAfterReadInterface[Type Gongstruct] interface {
OnAfterRead(stage *StageStruct,
instance *Type)
}
// OnAfterUpdateInterface callback when an instance is updated from the front
type OnAfterUpdateInterface[Type Gongstruct] interface {
OnAfterUpdate(stage *StageStruct, old, new *Type)
}
// OnAfterDeleteInterface callback when an instance is updated from the front
type OnAfterDeleteInterface[Type Gongstruct] interface {
OnAfterDelete(stage *StageStruct,
staged, front *Type)
}
type BackRepoInterface interface {
Commit(stage *StageStruct)
Checkout(stage *StageStruct)
Backup(stage *StageStruct, dirPath string)
Restore(stage *StageStruct, dirPath string)
BackupXL(stage *StageStruct, dirPath string)
RestoreXL(stage *StageStruct, dirPath string)
// insertion point for Commit and Checkout signatures
CommitAstruct(astruct *Astruct)
CheckoutAstruct(astruct *Astruct)
CommitAstructBstruct2Use(astructbstruct2use *AstructBstruct2Use)
CheckoutAstructBstruct2Use(astructbstruct2use *AstructBstruct2Use)
CommitAstructBstructUse(astructbstructuse *AstructBstructUse)
CheckoutAstructBstructUse(astructbstructuse *AstructBstructUse)
CommitBstruct(bstruct *Bstruct)
CheckoutBstruct(bstruct *Bstruct)
CommitDstruct(dstruct *Dstruct)
CheckoutDstruct(dstruct *Dstruct)
CommitFstruct(fstruct *Fstruct)
CheckoutFstruct(fstruct *Fstruct)
GetLastCommitFromBackNb() uint
GetLastPushFromFrontNb() uint
}
func NewStage(path string) (stage *StageStruct) {
stage = &StageStruct{ // insertion point for array initiatialisation
Astructs: make(map[*Astruct]any),
Astructs_mapString: make(map[string]*Astruct),
AstructBstruct2Uses: make(map[*AstructBstruct2Use]any),
AstructBstruct2Uses_mapString: make(map[string]*AstructBstruct2Use),
AstructBstructUses: make(map[*AstructBstructUse]any),
AstructBstructUses_mapString: make(map[string]*AstructBstructUse),
Bstructs: make(map[*Bstruct]any),
Bstructs_mapString: make(map[string]*Bstruct),
Dstructs: make(map[*Dstruct]any),
Dstructs_mapString: make(map[string]*Dstruct),
Fstructs: make(map[*Fstruct]any),
Fstructs_mapString: make(map[string]*Fstruct),
// end of insertion point
Map_GongStructName_InstancesNb: make(map[string]int),
path: path,
// to be removed after fix of [issue](https://github.com/golang/go/issues/57559)
Map_DocLink_Renaming: make(map[string]GONG__Identifier),
// the to be removed stops here
}
return
}
func (stage *StageStruct) GetPath() string {
return stage.path
}
func (stage *StageStruct) CommitWithSuspendedCallbacks() {
tmp := stage.OnInitCommitFromBackCallback
stage.OnInitCommitFromBackCallback = nil
stage.Commit()
stage.OnInitCommitFromBackCallback = tmp
}
func (stage *StageStruct) Commit() {
stage.ComputeReverseMaps()
if stage.BackRepo != nil {
stage.BackRepo.Commit(stage)
}
// insertion point for computing the map of number of instances per gongstruct
stage.Map_GongStructName_InstancesNb["Astruct"] = len(stage.Astructs)
stage.Map_GongStructName_InstancesNb["AstructBstruct2Use"] = len(stage.AstructBstruct2Uses)
stage.Map_GongStructName_InstancesNb["AstructBstructUse"] = len(stage.AstructBstructUses)
stage.Map_GongStructName_InstancesNb["Bstruct"] = len(stage.Bstructs)
stage.Map_GongStructName_InstancesNb["Dstruct"] = len(stage.Dstructs)
stage.Map_GongStructName_InstancesNb["Fstruct"] = len(stage.Fstructs)
}
func (stage *StageStruct) Checkout() {
if stage.BackRepo != nil {
stage.BackRepo.Checkout(stage)
}
stage.ComputeReverseMaps()
// insertion point for computing the map of number of instances per gongstruct
stage.Map_GongStructName_InstancesNb["Astruct"] = len(stage.Astructs)
stage.Map_GongStructName_InstancesNb["AstructBstruct2Use"] = len(stage.AstructBstruct2Uses)
stage.Map_GongStructName_InstancesNb["AstructBstructUse"] = len(stage.AstructBstructUses)
stage.Map_GongStructName_InstancesNb["Bstruct"] = len(stage.Bstructs)
stage.Map_GongStructName_InstancesNb["Dstruct"] = len(stage.Dstructs)
stage.Map_GongStructName_InstancesNb["Fstruct"] = len(stage.Fstructs)
}
// backup generates backup files in the dirPath
func (stage *StageStruct) Backup(dirPath string) {
if stage.BackRepo != nil {
stage.BackRepo.Backup(stage, dirPath)
}
}
// Restore resets Stage & BackRepo and restores their content from the restore files in dirPath
func (stage *StageStruct) Restore(dirPath string) {
if stage.BackRepo != nil {
stage.BackRepo.Restore(stage, dirPath)
}
}
// backup generates backup files in the dirPath
func (stage *StageStruct) BackupXL(dirPath string) {
if stage.BackRepo != nil {
stage.BackRepo.BackupXL(stage, dirPath)
}
}
// Restore resets Stage & BackRepo and restores their content from the restore files in dirPath
func (stage *StageStruct) RestoreXL(dirPath string) {
if stage.BackRepo != nil {
stage.BackRepo.RestoreXL(stage, dirPath)
}
}
// insertion point for cumulative sub template with model space calls
// Stage puts astruct to the model stage
func (astruct *Astruct) Stage(stage *StageStruct) *Astruct {
stage.Astructs[astruct] = __member
stage.Astructs_mapString[astruct.Name] = astruct
return astruct
}
// Unstage removes astruct off the model stage
func (astruct *Astruct) Unstage(stage *StageStruct) *Astruct {
delete(stage.Astructs, astruct)
delete(stage.Astructs_mapString, astruct.Name)
return astruct
}
// UnstageVoid removes astruct off the model stage
func (astruct *Astruct) UnstageVoid(stage *StageStruct) {
delete(stage.Astructs, astruct)
delete(stage.Astructs_mapString, astruct.Name)
}
// commit astruct to the back repo (if it is already staged)
func (astruct *Astruct) Commit(stage *StageStruct) *Astruct {
if _, ok := stage.Astructs[astruct]; ok {
if stage.BackRepo != nil {
stage.BackRepo.CommitAstruct(astruct)
}
}
return astruct
}
func (astruct *Astruct) CommitVoid(stage *StageStruct) {
astruct.Commit(stage)
}
// Checkout astruct to the back repo (if it is already staged)
func (astruct *Astruct) Checkout(stage *StageStruct) *Astruct {
if _, ok := stage.Astructs[astruct]; ok {
if stage.BackRepo != nil {
stage.BackRepo.CheckoutAstruct(astruct)
}
}
return astruct
}
// for satisfaction of GongStruct interface
func (astruct *Astruct) GetName() (res string) {
return astruct.Name
}
// Stage puts astructbstruct2use to the model stage
func (astructbstruct2use *AstructBstruct2Use) Stage(stage *StageStruct) *AstructBstruct2Use {
stage.AstructBstruct2Uses[astructbstruct2use] = __member
stage.AstructBstruct2Uses_mapString[astructbstruct2use.Name] = astructbstruct2use
return astructbstruct2use
}
// Unstage removes astructbstruct2use off the model stage
func (astructbstruct2use *AstructBstruct2Use) Unstage(stage *StageStruct) *AstructBstruct2Use {
delete(stage.AstructBstruct2Uses, astructbstruct2use)
delete(stage.AstructBstruct2Uses_mapString, astructbstruct2use.Name)
return astructbstruct2use
}
// UnstageVoid removes astructbstruct2use off the model stage
func (astructbstruct2use *AstructBstruct2Use) UnstageVoid(stage *StageStruct) {
delete(stage.AstructBstruct2Uses, astructbstruct2use)
delete(stage.AstructBstruct2Uses_mapString, astructbstruct2use.Name)
}
// commit astructbstruct2use to the back repo (if it is already staged)
func (astructbstruct2use *AstructBstruct2Use) Commit(stage *StageStruct) *AstructBstruct2Use {
if _, ok := stage.AstructBstruct2Uses[astructbstruct2use]; ok {
if stage.BackRepo != nil {
stage.BackRepo.CommitAstructBstruct2Use(astructbstruct2use)
}
}
return astructbstruct2use
}
func (astructbstruct2use *AstructBstruct2Use) CommitVoid(stage *StageStruct) {
astructbstruct2use.Commit(stage)
}
// Checkout astructbstruct2use to the back repo (if it is already staged)
func (astructbstruct2use *AstructBstruct2Use) Checkout(stage *StageStruct) *AstructBstruct2Use {
if _, ok := stage.AstructBstruct2Uses[astructbstruct2use]; ok {
if stage.BackRepo != nil {
stage.BackRepo.CheckoutAstructBstruct2Use(astructbstruct2use)
}
}
return astructbstruct2use
}
// for satisfaction of GongStruct interface
func (astructbstruct2use *AstructBstruct2Use) GetName() (res string) {
return astructbstruct2use.Name
}
// Stage puts astructbstructuse to the model stage
func (astructbstructuse *AstructBstructUse) Stage(stage *StageStruct) *AstructBstructUse {
stage.AstructBstructUses[astructbstructuse] = __member
stage.AstructBstructUses_mapString[astructbstructuse.Name] = astructbstructuse
return astructbstructuse
}
// Unstage removes astructbstructuse off the model stage
func (astructbstructuse *AstructBstructUse) Unstage(stage *StageStruct) *AstructBstructUse {
delete(stage.AstructBstructUses, astructbstructuse)
delete(stage.AstructBstructUses_mapString, astructbstructuse.Name)
return astructbstructuse
}
// UnstageVoid removes astructbstructuse off the model stage
func (astructbstructuse *AstructBstructUse) UnstageVoid(stage *StageStruct) {
delete(stage.AstructBstructUses, astructbstructuse)
delete(stage.AstructBstructUses_mapString, astructbstructuse.Name)
}
// commit astructbstructuse to the back repo (if it is already staged)
func (astructbstructuse *AstructBstructUse) Commit(stage *StageStruct) *AstructBstructUse {
if _, ok := stage.AstructBstructUses[astructbstructuse]; ok {
if stage.BackRepo != nil {
stage.BackRepo.CommitAstructBstructUse(astructbstructuse)
}
}
return astructbstructuse
}
func (astructbstructuse *AstructBstructUse) CommitVoid(stage *StageStruct) {
astructbstructuse.Commit(stage)
}
// Checkout astructbstructuse to the back repo (if it is already staged)
func (astructbstructuse *AstructBstructUse) Checkout(stage *StageStruct) *AstructBstructUse {
if _, ok := stage.AstructBstructUses[astructbstructuse]; ok {
if stage.BackRepo != nil {
stage.BackRepo.CheckoutAstructBstructUse(astructbstructuse)
}
}
return astructbstructuse
}
// for satisfaction of GongStruct interface
func (astructbstructuse *AstructBstructUse) GetName() (res string) {
return astructbstructuse.Name
}
// Stage puts bstruct to the model stage
func (bstruct *Bstruct) Stage(stage *StageStruct) *Bstruct {
stage.Bstructs[bstruct] = __member
stage.Bstructs_mapString[bstruct.Name] = bstruct
return bstruct
}
// Unstage removes bstruct off the model stage
func (bstruct *Bstruct) Unstage(stage *StageStruct) *Bstruct {
delete(stage.Bstructs, bstruct)
delete(stage.Bstructs_mapString, bstruct.Name)
return bstruct
}
// UnstageVoid removes bstruct off the model stage
func (bstruct *Bstruct) UnstageVoid(stage *StageStruct) {
delete(stage.Bstructs, bstruct)
delete(stage.Bstructs_mapString, bstruct.Name)
}
// commit bstruct to the back repo (if it is already staged)
func (bstruct *Bstruct) Commit(stage *StageStruct) *Bstruct {
if _, ok := stage.Bstructs[bstruct]; ok {
if stage.BackRepo != nil {
stage.BackRepo.CommitBstruct(bstruct)
}
}
return bstruct
}
func (bstruct *Bstruct) CommitVoid(stage *StageStruct) {
bstruct.Commit(stage)
}
// Checkout bstruct to the back repo (if it is already staged)
func (bstruct *Bstruct) Checkout(stage *StageStruct) *Bstruct {
if _, ok := stage.Bstructs[bstruct]; ok {
if stage.BackRepo != nil {
stage.BackRepo.CheckoutBstruct(bstruct)
}
}
return bstruct
}
// for satisfaction of GongStruct interface
func (bstruct *Bstruct) GetName() (res string) {
return bstruct.Name
}
// Stage puts dstruct to the model stage
func (dstruct *Dstruct) Stage(stage *StageStruct) *Dstruct {
stage.Dstructs[dstruct] = __member
stage.Dstructs_mapString[dstruct.Name] = dstruct
return dstruct
}
// Unstage removes dstruct off the model stage
func (dstruct *Dstruct) Unstage(stage *StageStruct) *Dstruct {
delete(stage.Dstructs, dstruct)
delete(stage.Dstructs_mapString, dstruct.Name)
return dstruct
}
// UnstageVoid removes dstruct off the model stage
func (dstruct *Dstruct) UnstageVoid(stage *StageStruct) {
delete(stage.Dstructs, dstruct)
delete(stage.Dstructs_mapString, dstruct.Name)
}
// commit dstruct to the back repo (if it is already staged)
func (dstruct *Dstruct) Commit(stage *StageStruct) *Dstruct {
if _, ok := stage.Dstructs[dstruct]; ok {
if stage.BackRepo != nil {
stage.BackRepo.CommitDstruct(dstruct)
}
}
return dstruct
}
func (dstruct *Dstruct) CommitVoid(stage *StageStruct) {
dstruct.Commit(stage)
}
// Checkout dstruct to the back repo (if it is already staged)
func (dstruct *Dstruct) Checkout(stage *StageStruct) *Dstruct {
if _, ok := stage.Dstructs[dstruct]; ok {
if stage.BackRepo != nil {
stage.BackRepo.CheckoutDstruct(dstruct)
}
}
return dstruct
}
// for satisfaction of GongStruct interface
func (dstruct *Dstruct) GetName() (res string) {
return dstruct.Name
}
// Stage puts fstruct to the model stage
func (fstruct *Fstruct) Stage(stage *StageStruct) *Fstruct {
stage.Fstructs[fstruct] = __member
stage.Fstructs_mapString[fstruct.Name] = fstruct
return fstruct
}
// Unstage removes fstruct off the model stage
func (fstruct *Fstruct) Unstage(stage *StageStruct) *Fstruct {
delete(stage.Fstructs, fstruct)
delete(stage.Fstructs_mapString, fstruct.Name)
return fstruct
}
// UnstageVoid removes fstruct off the model stage
func (fstruct *Fstruct) UnstageVoid(stage *StageStruct) {
delete(stage.Fstructs, fstruct)
delete(stage.Fstructs_mapString, fstruct.Name)
}
// commit fstruct to the back repo (if it is already staged)
func (fstruct *Fstruct) Commit(stage *StageStruct) *Fstruct {
if _, ok := stage.Fstructs[fstruct]; ok {
if stage.BackRepo != nil {
stage.BackRepo.CommitFstruct(fstruct)
}
}
return fstruct
}
func (fstruct *Fstruct) CommitVoid(stage *StageStruct) {
fstruct.Commit(stage)
}
// Checkout fstruct to the back repo (if it is already staged)
func (fstruct *Fstruct) Checkout(stage *StageStruct) *Fstruct {
if _, ok := stage.Fstructs[fstruct]; ok {
if stage.BackRepo != nil {
stage.BackRepo.CheckoutFstruct(fstruct)
}
}
return fstruct
}
// for satisfaction of GongStruct interface
func (fstruct *Fstruct) GetName() (res string) {
return fstruct.Name
}
// swagger:ignore
type AllModelsStructCreateInterface interface { // insertion point for Callbacks on creation
CreateORMAstruct(Astruct *Astruct)
CreateORMAstructBstruct2Use(AstructBstruct2Use *AstructBstruct2Use)
CreateORMAstructBstructUse(AstructBstructUse *AstructBstructUse)
CreateORMBstruct(Bstruct *Bstruct)
CreateORMDstruct(Dstruct *Dstruct)
CreateORMFstruct(Fstruct *Fstruct)
}
type AllModelsStructDeleteInterface interface { // insertion point for Callbacks on deletion
DeleteORMAstruct(Astruct *Astruct)
DeleteORMAstructBstruct2Use(AstructBstruct2Use *AstructBstruct2Use)
DeleteORMAstructBstructUse(AstructBstructUse *AstructBstructUse)
DeleteORMBstruct(Bstruct *Bstruct)
DeleteORMDstruct(Dstruct *Dstruct)
DeleteORMFstruct(Fstruct *Fstruct)
}
func (stage *StageStruct) Reset() { // insertion point for array reset
stage.Astructs = make(map[*Astruct]any)
stage.Astructs_mapString = make(map[string]*Astruct)
stage.AstructBstruct2Uses = make(map[*AstructBstruct2Use]any)
stage.AstructBstruct2Uses_mapString = make(map[string]*AstructBstruct2Use)
stage.AstructBstructUses = make(map[*AstructBstructUse]any)
stage.AstructBstructUses_mapString = make(map[string]*AstructBstructUse)
stage.Bstructs = make(map[*Bstruct]any)
stage.Bstructs_mapString = make(map[string]*Bstruct)
stage.Dstructs = make(map[*Dstruct]any)
stage.Dstructs_mapString = make(map[string]*Dstruct)
stage.Fstructs = make(map[*Fstruct]any)
stage.Fstructs_mapString = make(map[string]*Fstruct)
}
func (stage *StageStruct) Nil() { // insertion point for array nil
stage.Astructs = nil
stage.Astructs_mapString = nil
stage.AstructBstruct2Uses = nil
stage.AstructBstruct2Uses_mapString = nil
stage.AstructBstructUses = nil
stage.AstructBstructUses_mapString = nil
stage.Bstructs = nil
stage.Bstructs_mapString = nil
stage.Dstructs = nil
stage.Dstructs_mapString = nil
stage.Fstructs = nil
stage.Fstructs_mapString = nil
}
func (stage *StageStruct) Unstage() { // insertion point for array nil
for astruct := range stage.Astructs {
astruct.Unstage(stage)
}
for astructbstruct2use := range stage.AstructBstruct2Uses {
astructbstruct2use.Unstage(stage)
}
for astructbstructuse := range stage.AstructBstructUses {
astructbstructuse.Unstage(stage)
}
for bstruct := range stage.Bstructs {
bstruct.Unstage(stage)
}
for dstruct := range stage.Dstructs {
dstruct.Unstage(stage)
}
for fstruct := range stage.Fstructs {
fstruct.Unstage(stage)
}
}
// Gongstruct is the type parameter for generated generic function that allows
// - access to staged instances
// - navigation between staged instances by going backward association links between gongstruct
// - full refactoring of Gongstruct identifiers / fields
type Gongstruct interface {
// insertion point for generic types
Astruct | AstructBstruct2Use | AstructBstructUse | Bstruct | Dstruct | Fstruct
}
type GongtructBasicField interface {
int | float64 | bool | string | time.Time | time.Duration
}
// Gongstruct is the type parameter for generated generic function that allows
// - access to staged instances
// - navigation between staged instances by going backward association links between gongstruct
// - full refactoring of Gongstruct identifiers / fields
type PointerToGongstruct interface {
// insertion point for generic types
*Astruct | *AstructBstruct2Use | *AstructBstructUse | *Bstruct | *Dstruct | *Fstruct
GetName() string
CommitVoid(*StageStruct)
UnstageVoid(stage *StageStruct)
}
func CompareGongstructByName[T PointerToGongstruct](a, b T) int {
return cmp.Compare(a.GetName(), b.GetName())
}
func SortGongstructSetByName[T PointerToGongstruct](set map[T]any) (sortedSlice []T) {
sortedSlice = maps.Keys(set)
slices.SortFunc(sortedSlice, CompareGongstructByName)
return
}
func GetGongstrucsSorted[T PointerToGongstruct](stage *StageStruct) (sortedSlice []T) {
set := GetGongstructInstancesSetFromPointerType[T](stage)
sortedSlice = SortGongstructSetByName(*set)
return
}
type GongstructSet interface {
map[any]any |
// insertion point for generic types
map[*Astruct]any |
map[*AstructBstruct2Use]any |
map[*AstructBstructUse]any |
map[*Bstruct]any |
map[*Dstruct]any |
map[*Fstruct]any |
map[*any]any // because go does not support an extra "|" at the end of type specifications
}
type GongstructMapString interface {
map[any]any |
// insertion point for generic types
map[string]*Astruct |
map[string]*AstructBstruct2Use |
map[string]*AstructBstructUse |
map[string]*Bstruct |
map[string]*Dstruct |
map[string]*Fstruct |
map[*any]any // because go does not support an extra "|" at the end of type specifications
}
// GongGetSet returns the set staged GongstructType instances
// it is usefull because it allows refactoring of gong struct identifier
func GongGetSet[Type GongstructSet](stage *StageStruct) *Type {
var ret Type
switch any(ret).(type) {
// insertion point for generic get functions
case map[*Astruct]any:
return any(&stage.Astructs).(*Type)
case map[*AstructBstruct2Use]any:
return any(&stage.AstructBstruct2Uses).(*Type)
case map[*AstructBstructUse]any:
return any(&stage.AstructBstructUses).(*Type)
case map[*Bstruct]any:
return any(&stage.Bstructs).(*Type)
case map[*Dstruct]any:
return any(&stage.Dstructs).(*Type)
case map[*Fstruct]any:
return any(&stage.Fstructs).(*Type)
default:
return nil
}
}
// GongGetMap returns the map of staged GongstructType instances
// it is usefull because it allows refactoring of gong struct identifier
func GongGetMap[Type GongstructMapString](stage *StageStruct) *Type {
var ret Type
switch any(ret).(type) {
// insertion point for generic get functions
case map[string]*Astruct:
return any(&stage.Astructs_mapString).(*Type)
case map[string]*AstructBstruct2Use:
return any(&stage.AstructBstruct2Uses_mapString).(*Type)
case map[string]*AstructBstructUse:
return any(&stage.AstructBstructUses_mapString).(*Type)
case map[string]*Bstruct:
return any(&stage.Bstructs_mapString).(*Type)
case map[string]*Dstruct:
return any(&stage.Dstructs_mapString).(*Type)
case map[string]*Fstruct:
return any(&stage.Fstructs_mapString).(*Type)
default:
return nil
}
}
// GetGongstructInstancesSet returns the set staged GongstructType instances
// it is usefull because it allows refactoring of gongstruct identifier
func GetGongstructInstancesSet[Type Gongstruct](stage *StageStruct) *map[*Type]any {
var ret Type
switch any(ret).(type) {
// insertion point for generic get functions
case Astruct:
return any(&stage.Astructs).(*map[*Type]any)
case AstructBstruct2Use:
return any(&stage.AstructBstruct2Uses).(*map[*Type]any)
case AstructBstructUse:
return any(&stage.AstructBstructUses).(*map[*Type]any)
case Bstruct:
return any(&stage.Bstructs).(*map[*Type]any)
case Dstruct:
return any(&stage.Dstructs).(*map[*Type]any)
case Fstruct:
return any(&stage.Fstructs).(*map[*Type]any)
default:
return nil
}
}
// GetGongstructInstancesSetFromPointerType returns the set staged GongstructType instances
// it is usefull because it allows refactoring of gongstruct identifier
func GetGongstructInstancesSetFromPointerType[Type PointerToGongstruct](stage *StageStruct) *map[Type]any {
var ret Type
switch any(ret).(type) {
// insertion point for generic get functions
case *Astruct:
return any(&stage.Astructs).(*map[Type]any)
case *AstructBstruct2Use:
return any(&stage.AstructBstruct2Uses).(*map[Type]any)
case *AstructBstructUse:
return any(&stage.AstructBstructUses).(*map[Type]any)
case *Bstruct:
return any(&stage.Bstructs).(*map[Type]any)
case *Dstruct:
return any(&stage.Dstructs).(*map[Type]any)
case *Fstruct:
return any(&stage.Fstructs).(*map[Type]any)
default:
return nil
}
}
// GetGongstructInstancesMap returns the map of staged GongstructType instances
// it is usefull because it allows refactoring of gong struct identifier
func GetGongstructInstancesMap[Type Gongstruct](stage *StageStruct) *map[string]*Type {
var ret Type
switch any(ret).(type) {
// insertion point for generic get functions
case Astruct:
return any(&stage.Astructs_mapString).(*map[string]*Type)
case AstructBstruct2Use:
return any(&stage.AstructBstruct2Uses_mapString).(*map[string]*Type)
case AstructBstructUse:
return any(&stage.AstructBstructUses_mapString).(*map[string]*Type)
case Bstruct:
return any(&stage.Bstructs_mapString).(*map[string]*Type)
case Dstruct:
return any(&stage.Dstructs_mapString).(*map[string]*Type)
case Fstruct:
return any(&stage.Fstructs_mapString).(*map[string]*Type)
default:
return nil
}
}
// GetAssociationName is a generic function that returns an instance of Type
// where each association is filled with an instance whose name is the name of the association
//
// This function can be handy for generating navigation function that are refactorable
func GetAssociationName[Type Gongstruct]() *Type {
var ret Type
switch any(ret).(type) {
// insertion point for instance with special fields
case Astruct:
return any(&Astruct{
// Initialisation of associations
// field is initialized with an instance of Bstruct with the name of the field
Associationtob: &Bstruct{Name: "Associationtob"},
// field is initialized with an instance of Bstruct with the name of the field
Anarrayofb: []*Bstruct{{Name: "Anarrayofb"}},
// field is initialized with an instance of Bstruct with the name of the field
Anotherassociationtob_2: &Bstruct{Name: "Anotherassociationtob_2"},
// field is initialized with an instance of Astruct with the name of the field
Anarrayofa: []*Astruct{{Name: "Anarrayofa"}},
// field is initialized with an instance of Bstruct with the name of the field
Anotherarrayofb: []*Bstruct{{Name: "Anotherarrayofb"}},
// field is initialized with an instance of AstructBstructUse with the name of the field
AnarrayofbUse: []*AstructBstructUse{{Name: "AnarrayofbUse"}},
// field is initialized with an instance of AstructBstruct2Use with the name of the field
Anarrayofb2Use: []*AstructBstruct2Use{{Name: "Anarrayofb2Use"}},
// field is initialized with an instance of Astruct with the name of the field
AnAstruct: &Astruct{Name: "AnAstruct"},
// field is initialized with Cstruct as it is a composite
Cstruct: Cstruct{
// per field init
//
Bstruct: &Bstruct{Name: "Bstruct"},
//
Bstruct2: &Bstruct{Name: "Bstruct2"},
//
Dstruct: &Dstruct{Name: "Dstruct"},
//
Dstruct2: &Dstruct{Name: "Dstruct2"},
},
// field is initialized with Estruct as it is a composite
Estruct: Estruct{
// per field init
//
Dstruct3: &Dstruct{Name: "Dstruct3"},
//
Dstruct4: &Dstruct{Name: "Dstruct4"},
},
}).(*Type)
case AstructBstruct2Use:
return any(&AstructBstruct2Use{
// Initialisation of associations
// field is initialized with an instance of Bstruct with the name of the field
Bstrcut2: &Bstruct{Name: "Bstrcut2"},
}).(*Type)
case AstructBstructUse:
return any(&AstructBstructUse{
// Initialisation of associations
// field is initialized with an instance of Bstruct with the name of the field
Bstruct2: &Bstruct{Name: "Bstruct2"},
}).(*Type)
case Bstruct:
return any(&Bstruct{
// Initialisation of associations
}).(*Type)
case Dstruct:
return any(&Dstruct{
// Initialisation of associations
// field is initialized with an instance of Bstruct with the name of the field
Anarrayofb: []*Bstruct{{Name: "Anarrayofb"}},
}).(*Type)
case Fstruct:
return any(&Fstruct{
// Initialisation of associations
}).(*Type)
default:
return nil
}
}
// GetPointerReverseMap allows backtrack navigation of any Start.Fieldname
// associations (0..1) that is a pointer from one staged Gongstruct (type Start)
// instances to another (type End)
//
// The function provides a map with keys as instances of End and values to arrays of *Start
// the map is construed by iterating over all Start instances and populationg keys with End instances
// and values with slice of Start instances
func GetPointerReverseMap[Start, End Gongstruct](fieldname string, stage *StageStruct) map[*End][]*Start {
var ret Start
switch any(ret).(type) {
// insertion point of functions that provide maps for reverse associations
// reverse maps of direct associations of Astruct
case Astruct:
switch fieldname {
// insertion point for per direct association field
case "Associationtob":
res := make(map[*Bstruct][]*Astruct)
for astruct := range stage.Astructs {
if astruct.Associationtob != nil {
bstruct_ := astruct.Associationtob
var astructs []*Astruct
_, ok := res[bstruct_]
if ok {
astructs = res[bstruct_]
} else {
astructs = make([]*Astruct, 0)
}
astructs = append(astructs, astruct)
res[bstruct_] = astructs
}
}
return any(res).(map[*End][]*Start)