-
Notifications
You must be signed in to change notification settings - Fork 14
/
orm_engine.go
47 lines (39 loc) · 1.19 KB
/
orm_engine.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
package registry
import (
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/config"
"github.com/latolukasz/orm"
"github.com/sarulabs/di"
)
func ServiceDefinitionOrmEngine() *service.Definition {
return serviceDefinitionOrmEngine(true, false)
}
func ServiceDefinitionOrmEngineForContext(enableGraphQLDataLoader bool) *service.Definition {
return serviceDefinitionOrmEngine(false, enableGraphQLDataLoader)
}
func serviceDefinitionOrmEngine(global bool, enableGraphQLDataLoader bool) *service.Definition {
suffix := "request"
if global {
suffix = "global"
}
return &service.Definition{
Name: "orm_engine_" + suffix,
Global: global,
Build: func(ctn di.Container) (interface{}, error) {
ormConfigService, err := ctn.SafeGet(service.ORMConfigService)
if err != nil {
return nil, err
}
ormEngine := ormConfigService.(orm.ValidatedRegistry).CreateEngine()
if !global && enableGraphQLDataLoader {
ormEngine.EnableRequestCache()
}
configService := ctn.Get(service.ConfigService).(config.IConfig)
ormDebug, ok := configService.Bool("orm_debug")
if ok && ormDebug {
ormEngine.EnableQueryDebug()
}
return ormEngine, nil
},
}
}