26 lines
468 B
Go
26 lines
468 B
Go
package db
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestNew(t *testing.T) {
|
|
mdb, err := New(WithMysql("127.0.0.1", 2881, "yizhi@test", "yizhi", "mie"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
type User struct {
|
|
Id uint64 `gorm:"primaryKey"`
|
|
Username string `gorm:"unique"`
|
|
}
|
|
|
|
if err = mdb.Session(t.Context()).AutoMigrate(&User{}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err = mdb.Session(t.Context()).Create(&User{Username: "zyp"}).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|