-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_instance_db_from_instance.go
79 lines (71 loc) · 1.74 KB
/
get_instance_db_from_instance.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
// generated code - do not edit
package orm
import (
"github.com/fullstack-lang/gong/test2/go/models"
)
type GongstructDB interface {
// insertion point for generic types
// "int" is present to handle the case when no struct is present
int | ADB | BDB
}
func GetInstanceDBFromInstance[T models.Gongstruct, T2 GongstructDB](
stage *models.StageStruct,
backRepo *BackRepoStruct,
instance *T) (ret *T2) {
switch concreteInstance := any(instance).(type) {
// insertion point for per struct backup
case *models.A:
aInstance := any(concreteInstance).(*models.A)
ret2 := backRepo.BackRepoA.GetADBFromAPtr(aInstance)
ret = any(ret2).(*T2)
case *models.B:
bInstance := any(concreteInstance).(*models.B)
ret2 := backRepo.BackRepoB.GetBDBFromBPtr(bInstance)
ret = any(ret2).(*T2)
default:
_ = concreteInstance
}
return
}
func GetID[T models.Gongstruct](
stage *models.StageStruct,
backRepo *BackRepoStruct,
instance *T) (id int) {
switch inst := any(instance).(type) {
// insertion point for per struct backup
case *models.A:
tmp := GetInstanceDBFromInstance[models.A, ADB](
stage, backRepo, inst,
)
id = int(tmp.ID)
case *models.B:
tmp := GetInstanceDBFromInstance[models.B, BDB](
stage, backRepo, inst,
)
id = int(tmp.ID)
default:
_ = inst
}
return
}
func GetIDPointer[T models.PointerToGongstruct](
stage *models.StageStruct,
backRepo *BackRepoStruct,
instance T) (id int) {
switch inst := any(instance).(type) {
// insertion point for per struct backup
case *models.A:
tmp := GetInstanceDBFromInstance[models.A, ADB](
stage, backRepo, inst,
)
id = int(tmp.ID)
case *models.B:
tmp := GetInstanceDBFromInstance[models.B, BDB](
stage, backRepo, inst,
)
id = int(tmp.ID)
default:
_ = inst
}
return
}