mycommon/mymysql/mysql_test.go

34 lines
619 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
}
2024-06-01 18:28:09 +08:00
defer CloseAllDB()
2023-01-15 00:21:08 +08:00
var res = make(map[string]interface{})
2024-06-01 18:17:41 +08:00
err = 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)
}