mycommon/mymysql/mysql_test.go

34 lines
617 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-03-20 20:41:36 +08:00
myDB, err := NewDefault(&Config{
2023-01-15 00:21:08 +08:00
Dsn: "root:root@tcp(127.0.0.1:3306)/site?loc=Local&charset=utf8mb4&writeTimeout=3s&readTimeout=3s&timeout=2s&parseTime=true",
MaxOpenConn: 16,
MaxIdleConn: 4,
MaxIdleTime: "5m",
MaxLifeTime: "30m",
Debug: false,
GormLogger: nil,
})
if err != nil {
fmt.Println(err)
return
}
defer myDB.Close()
var res = make(map[string]interface{})
2023-03-20 20:41:36 +08:00
err = myDB.db.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)
}