/
adaptors.go
83 lines (76 loc) · 2.32 KB
/
adaptors.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
package adaptors
import (
"github.com/e154/smart-home/system/config"
"github.com/e154/smart-home/system/migrations"
"github.com/jinzhu/gorm"
"github.com/op/go-logging"
)
var (
log = logging.MustGetLogger("adaptors")
)
type Adaptors struct {
Node *Node
Script *Script
Workflow *Workflow
WorkflowScenario *WorkflowScenario
Device *Device
DeviceAction *DeviceAction
DeviceState *DeviceState
Flow *Flow
FlowElement *FlowElement
Connection *Connection
Worker *Worker
Role *Role
Permission *Permission
User *User
UserMeta *UserMeta
Image *Image
Variable *Variable
Map *Map
MapLayer *MapLayer
MapText *MapText
MapImage *MapImage
MapDevice *MapDevice
MapElement *MapElement
MapDeviceState *MapDeviceState
MapDeviceAction *MapDeviceAction
Log *Log
MapZone *MapZone
}
func NewAdaptors(db *gorm.DB,
cfg *config.AppConfig,
migrations *migrations.Migrations) (adaptors *Adaptors) {
if cfg.AutoMigrate {
migrations.Up()
}
adaptors = &Adaptors{
Node: GetNodeAdaptor(db),
Script: GetScriptAdaptor(db),
Workflow: GetWorkflowAdaptor(db),
WorkflowScenario: GetWorkflowScenarioAdaptor(db),
Device: GetDeviceAdaptor(db),
DeviceAction: GetDeviceActionAdaptor(db),
DeviceState: GetDeviceStateAdaptor(db),
Flow: GetFlowAdaptor(db),
FlowElement: GetFlowElementAdaptor(db),
Connection: GetConnectionAdaptor(db),
Worker: GetWorkerAdaptor(db),
Role: GetRoleAdaptor(db),
Permission: GetPermissionAdaptor(db),
User: GetUserAdaptor(db),
UserMeta: GetUserMetaAdaptor(db),
Image: GetImageAdaptor(db),
Variable: GetVariableAdaptor(db),
Map: GetMapAdaptor(db),
MapLayer: GetMapLayerAdaptor(db),
MapText: GetMapTextAdaptor(db),
MapImage: GetMapImageAdaptor(db),
MapDevice: GetMapDeviceAdaptor(db),
MapElement: GetMapElementAdaptor(db),
MapDeviceState: GetMapDeviceStateAdaptor(db),
MapDeviceAction: GetMapDeviceActionAdaptor(db),
Log: GetLogAdaptor(db),
MapZone: GetMapZoneAdaptor(db),
}
return
}