-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
41 lines (36 loc) · 938 Bytes
/
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
package xdb
import (
"reflect"
"time"
"github.com/zhiyunliu/glue/xdb"
)
// DB 数据库配置
type Setting struct {
ConnName string `json:"-"`
Cfg *xdb.Config `json:"-"`
slowThreshold time.Duration `json:"-"`
logger xdb.Logger `json:"-"`
}
// New 构建DB连接信息
func NewConfig(connName string, opts ...xdb.Option) *Setting {
db := &Setting{
ConnName: connName,
Cfg: &xdb.Config{
MaxOpen: xdb.Default.MaxOpen,
MaxIdle: xdb.Default.MaxIdle,
LifeTime: xdb.Default.LifeTime,
ShowQueryLog: xdb.Default.ShowQueryLog,
LongQueryTime: xdb.Default.LongQueryTime,
LoggerName: xdb.Default.LoggerName,
Debug: xdb.Default.Debug,
},
}
for _, opt := range opts {
opt(db.Cfg)
}
return db
}
// 注册自定义类型转换
func RegisterDbType(dbType string, reflectType reflect.Type) error {
return xdb.RegisterDbType(dbType, reflectType)
}