-
Notifications
You must be signed in to change notification settings - Fork 13
/
orm_config.go
42 lines (32 loc) · 963 Bytes
/
orm_config.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
package registry
import (
"errors"
"fmt"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/config"
"github.com/sarulabs/di"
"github.com/latolukasz/orm"
)
type ORMRegistryInitFunc func(registry *orm.Registry)
func ServiceDefinitionOrmRegistry(init ORMRegistryInitFunc) *service.Definition {
return &service.Definition{
Name: service.ORMConfigService,
Global: true,
Build: func(ctn di.Container) (interface{}, error) {
configService := ctn.Get(service.ConfigService).(config.IConfig)
registry := orm.NewRegistry()
configuration, ok := configService.Get("orm")
if !ok {
return nil, errors.New("no orm config")
}
yamlConfig := map[string]interface{}{}
for k, v := range configuration.(map[interface{}]interface{}) {
yamlConfig[fmt.Sprint(k)] = v
}
registry.InitByYaml(yamlConfig)
init(registry)
ormConfig, err := registry.Validate()
return ormConfig, err
},
}
}