forked from micanzhang/xorm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
engine_option.go
115 lines (96 loc) · 2.02 KB
/
engine_option.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
package xorm
import (
"context"
"os"
"time"
"github.com/lingochamp/core"
)
// Option config Engine behavior
type Option func(x *Engine)
func EnableTraceOption(enable bool) Option {
return func(x *Engine) {
core.EnableTraceOption(enable)(x.db)
}
}
func ColumnMapperOption(im core.IMapper) Option {
return func(x *Engine) {
x.ColumnMapper = im
}
}
func TableMapperOption(im core.IMapper) Option {
return func(x *Engine) {
x.TableMapper = im
}
}
func LoggerOption(l func(context.Context) core.ILogger) Option {
return func(x *Engine) {
x.logger = l
}
}
func ShowSQLOption(show bool) Option {
return func(x *Engine) {
x.showSQL = show
}
}
func ShowExecTimeOption(show bool) Option {
return func(x *Engine) {
x.showExecTime = show
}
}
func DisableGlobalCacheOption(disable bool) Option {
return func(x *Engine) {
x.disableGlobalCache = disable
}
}
func TZLocationOption(local *time.Location) Option {
return func(x *Engine) {
x.SetTZLocation(local)
}
}
func TZDatabaseOption(local *time.Location) Option {
return func(x *Engine) {
x.SetTZDatabase(local)
}
}
func MaxOpenConnsOption(conns int) Option {
return func(x *Engine) {
x.SetMaxOpenConns(conns)
}
}
func MaxIdleConnsOption(conns int) Option {
return func(x *Engine) {
x.SetMaxIdleConns(conns)
}
}
func ConnMaxLifetimeOption(d time.Duration) Option {
return func(x *Engine) {
x.SetConnMaxLifetime(d)
}
}
func MapperOption(mapper core.IMapper) Option {
return func(x *Engine) {
x.SetMapper(mapper)
}
}
func DefaultCacherOption(cacher core.Cacher) Option {
return func(x *Engine) {
x.SetDefaultCacher(cacher)
}
}
func defaultOptions() []Option {
logger := NewSimpleLogger(os.Stdout)
logger.SetLevel(core.LOG_INFO)
dbTZOption := func(x *Engine) {
local := time.Local
if x.dialect.DBType() == core.SQLITE {
local = time.UTC
}
x.SetTZDatabase(local)
}
return []Option{
LoggerOption(func(context.Context) core.ILogger { return logger }),
TZLocationOption(time.Local),
dbTZOption,
MapperOption(new(core.SnakeMapper)),
}
}