package main
import (
"context"
"github.com/Basis-Health/godbpool"
"github.com/Basis-Health/godbpool/gormpool"
"log"
"time"
)
func main() {
// config options
opts := gormpool.Options{
Type: godbpool.MySQL,
Args: "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8&parseTime=True",
KeepConn: 2,
Capacity: 5,
MaxWaitDuration: 2000 * time.Millisecond,
}
// create a pool
p, err := gormpool.NewPool(context.Background(), opts)
if err != nil {
log.Println(err)
return
}
// Get a conn
conn, err := p.Get()
if err != nil {
log.Println(err)
}
// ... do some CURD
// put conn back to pool
p.Put(conn)
// check the pool status
p.Status()
// close pool
p.Close()
}