Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

GORM手册

连接数据库

导入驱动

1
import _ "github.com/go-sql-driver/mysql"
1
2
3
4
5
6
7
8
9
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
)

func main() {
db, err := gorm.Open("mysql", "user:password@tcp(port)/dbname?charset=utf8&parseTime=True&loc=Local")
defer db.Close()
}

模型

评论