mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 15:04:45 +08:00
mysql 增加一个连接池设置
This commit is contained in:
@@ -206,7 +206,7 @@ func (slf *DBResult) mapSlice2interface(data []map[string]string, in interface{}
|
||||
}
|
||||
|
||||
// Connect ...
|
||||
func (slf *DBModule) Connect() error {
|
||||
func (slf *DBModule) Connect(maxConn int) error {
|
||||
cmd := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true&loc=%s",
|
||||
slf.UserName,
|
||||
slf.Password,
|
||||
@@ -225,6 +225,10 @@ func (slf *DBModule) Connect() error {
|
||||
return err
|
||||
}
|
||||
slf.db = db
|
||||
db.SetMaxOpenConns(maxConn)
|
||||
db.SetMaxIdleConns(maxConn)
|
||||
db.SetConnMaxLifetime(time.Second * 90)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ func TestDBModule(t *testing.T) {
|
||||
Password: "Root!!2018",
|
||||
DBName: "QuantFundsDB",
|
||||
}
|
||||
db.Connect()
|
||||
db.Connect(100)
|
||||
|
||||
res := db.Query("select * from tbl_fun_heelthrow where id >= 1")
|
||||
if res.Err != nil {
|
||||
@@ -26,7 +26,7 @@ func TestDBModule(t *testing.T) {
|
||||
Uuid string `json:"uuid,omitempty"`
|
||||
AAAA string `json:"xxx"`
|
||||
}{}
|
||||
err := res.SetSpecificTag("json").SetBlurMode(false).UnMarshal(&out)
|
||||
err := res.SetSpecificTag("json").SetBlurMode(true).UnMarshal(&out)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user