fix issue: database connection pool does not work expectly

This commit is contained in:
John
2018-12-12 20:01:10 +08:00
parent 670993f769
commit 105a821069
6 changed files with 85 additions and 41 deletions

View File

@ -0,0 +1,36 @@
package main
import (
"gitee.com/johng/gf/g/database/gdb"
"time"
)
func main() {
gdb.AddDefaultConfigNode(gdb.ConfigNode {
Host : "127.0.0.1",
Port : "3306",
User : "root",
Pass : "12345678",
Name : "test",
Type : "mysql",
Role : "master",
Charset : "utf8",
MaxIdleConnCount : 10,
MaxOpenConnCount : 10,
MaxConnLifetime : 10,
})
db, err := gdb.New()
if err != nil {
panic(err)
}
// 开启调试模式以便于记录所有执行的SQL
db.SetDebug(true)
for {
for i := 0; i < 10; i++ {
go db.Table("user").All()
}
time.Sleep(time.Second)
}
}

View File

@ -1,9 +1,8 @@
package main
import (
"gitee.com/johng/gf/g/database/gdb"
"fmt"
"gitee.com/johng/gf/g/encoding/gparser"
"gitee.com/johng/gf/g/database/gdb"
)
func main() {
@ -27,8 +26,5 @@ func main() {
r, _ := db.Table("user").All()
if r != nil {
fmt.Println(r.ToList())
b, e := gparser.VarToJson(r.ToList())
fmt.Println(e)
fmt.Println(string(b))
}
}