GORM MySQL Driver
Quick Start
import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
dsn := "gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
Configuration
import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
var datetimePrecision = 2
db, err := gorm.Open(mysql.New(mysql.Config{
DSN: "gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True&loc=Local",
DefaultStringSize: 256,
DisableDatetimePrecision: true,
DefaultDatetimePrecision: &datetimePrecision,
DontSupportRenameIndex: true,
DontSupportRenameColumn: true,
SkipInitializeWithVersion: false,
}), &gorm.Config{})
Customized Driver
import (
_ "example.com/my_mysql_driver"
"gorm.io/gorm"
"gorm.io/driver/mysql"
)
db, err := gorm.Open(mysql.New(mysql.Config{
DriverName: "my_mysql_driver_name",
DSN: "gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True&loc=Local",
})
Checkout https://gorm.io for details.