mycommon/mymysql/mysql_test.go

34 lines
631 B
Go
Raw Normal View History

2023-01-15 00:21:08 +08:00
package mymysql
import (
"fmt"
"testing"
)
func TestMysql(t *testing.T) {
2023-04-21 18:18:58 +08:00
err := InitDefault(&Config{
Dsn: "root:Tqa129126@tcp(119.29.187.200:3306)/site?loc=Local&charset=utf8mb4&writeTimeout=3s&readTimeout=3s&timeout=2s&parseTime=true",
2023-01-15 00:21:08 +08:00
MaxOpenConn: 16,
MaxIdleConn: 4,
MaxIdleTime: "5m",
MaxLifeTime: "30m",
Debug: false,
GormLogger: nil,
})
if err != nil {
fmt.Println(err)
return
}
2023-05-18 17:52:26 +08:00
defer CloseAllInstance()
2023-01-15 00:21:08 +08:00
var res = make(map[string]interface{})
2023-04-21 18:18:58 +08:00
err = Instance().Table("image").Limit(1).Take(&res).Error
2023-01-15 00:21:08 +08:00
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v\n", res)
}