Files
packages/database/db/new_test.go
2025-10-31 22:23:35 +08:00

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)
}
}