-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_instance_db_from_instance.go
121 lines (113 loc) · 3.46 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
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
// generated code - do not edit
package orm
import (
"github.com/fullstack-lang/gongsim/go/models"
)
type GongstructDB interface {
// insertion point for generic types
// "int" is present to handle the case when no struct is present
int | DummyAgentDB | EngineDB | EventDB | GongsimCommandDB | GongsimStatusDB
}
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.DummyAgent:
dummyagentInstance := any(concreteInstance).(*models.DummyAgent)
ret2 := backRepo.BackRepoDummyAgent.GetDummyAgentDBFromDummyAgentPtr(dummyagentInstance)
ret = any(ret2).(*T2)
case *models.Engine:
engineInstance := any(concreteInstance).(*models.Engine)
ret2 := backRepo.BackRepoEngine.GetEngineDBFromEnginePtr(engineInstance)
ret = any(ret2).(*T2)
case *models.Event:
eventInstance := any(concreteInstance).(*models.Event)
ret2 := backRepo.BackRepoEvent.GetEventDBFromEventPtr(eventInstance)
ret = any(ret2).(*T2)
case *models.GongsimCommand:
gongsimcommandInstance := any(concreteInstance).(*models.GongsimCommand)
ret2 := backRepo.BackRepoGongsimCommand.GetGongsimCommandDBFromGongsimCommandPtr(gongsimcommandInstance)
ret = any(ret2).(*T2)
case *models.GongsimStatus:
gongsimstatusInstance := any(concreteInstance).(*models.GongsimStatus)
ret2 := backRepo.BackRepoGongsimStatus.GetGongsimStatusDBFromGongsimStatusPtr(gongsimstatusInstance)
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.DummyAgent:
tmp := GetInstanceDBFromInstance[models.DummyAgent, DummyAgentDB](
stage, backRepo, inst,
)
id = int(tmp.ID)
case *models.Engine:
tmp := GetInstanceDBFromInstance[models.Engine, EngineDB](
stage, backRepo, inst,
)
id = int(tmp.ID)
case *models.Event:
tmp := GetInstanceDBFromInstance[models.Event, EventDB](
stage, backRepo, inst,
)
id = int(tmp.ID)
case *models.GongsimCommand:
tmp := GetInstanceDBFromInstance[models.GongsimCommand, GongsimCommandDB](
stage, backRepo, inst,
)
id = int(tmp.ID)
case *models.GongsimStatus:
tmp := GetInstanceDBFromInstance[models.GongsimStatus, GongsimStatusDB](
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.DummyAgent:
tmp := GetInstanceDBFromInstance[models.DummyAgent, DummyAgentDB](
stage, backRepo, inst,
)
id = int(tmp.ID)
case *models.Engine:
tmp := GetInstanceDBFromInstance[models.Engine, EngineDB](
stage, backRepo, inst,
)
id = int(tmp.ID)
case *models.Event:
tmp := GetInstanceDBFromInstance[models.Event, EventDB](
stage, backRepo, inst,
)
id = int(tmp.ID)
case *models.GongsimCommand:
tmp := GetInstanceDBFromInstance[models.GongsimCommand, GongsimCommandDB](
stage, backRepo, inst,
)
id = int(tmp.ID)
case *models.GongsimStatus:
tmp := GetInstanceDBFromInstance[models.GongsimStatus, GongsimStatusDB](
stage, backRepo, inst,
)
id = int(tmp.ID)
default:
_ = inst
}
return
}