forked from ezbuy/redis-orm
/
gen.conf.mssql.go
50 lines (44 loc) · 962 Bytes
/
gen.conf.mssql.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
package model
import (
"sync"
"time"
"gopkg.in/ezbuy/redis-orm.v1/orm"
)
var (
_mssql_store *orm.DBStore
_mssql_cfg MsSQLConfig
_mssql_once sync.Once
)
type MsSQLConfig struct {
Host string
Port int
UserName string
Password string
Database string
PoolSize int
ConnMaxLifeTime time.Duration
}
func MsSQLSetup(cf *MsSQLConfig) {
_mssql_cfg = *cf
}
func MsSQL() *orm.DBStore {
var err error
_mssql_once.Do(func() {
_mssql_store, err = orm.NewDBStore("mssql",
_mssql_cfg.Host,
_mssql_cfg.Port,
_mssql_cfg.Database,
_mssql_cfg.UserName,
_mssql_cfg.Password)
if err != nil {
panic(err)
}
_mssql_store.SetConnMaxLifetime(time.Hour)
if _mssql_cfg.ConnMaxLifeTime > 0 {
_mssql_store.SetConnMaxLifetime(_mssql_cfg.ConnMaxLifeTime)
}
_mssql_store.SetMaxIdleConns(_mssql_cfg.PoolSize)
_mssql_store.SetMaxOpenConns(_mssql_cfg.PoolSize)
})
return _mssql_store
}