mirror of
https://gitee.com/johng/gf
synced 2026-07-08 06:35:16 +08:00
fix issue: database connection pool does not work expectly
This commit is contained in:
36
geg/database/orm/mysql/gdb_pool.go
Normal file
36
geg/database/orm/mysql/gdb_pool.go
Normal 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)
|
||||
}
|
||||
|
||||
}
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user