fix(db): need to set charset, parseTime and loc in connection for mysql

This commit is contained in:
Derrick Hammer 2023-06-29 02:54:31 -04:00
parent 993b9e8208
commit 5d15ca330a
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 2 additions and 2 deletions

View File

@ -35,9 +35,9 @@ func Init() {
// Connect to a MySQL database. // Connect to a MySQL database.
case "mysql": case "mysql":
if dbSocket != "" { if dbSocket != "" {
dsn = fmt.Sprintf("%s:%s@unix(%s)/%s", dbUser, dbPassword, dbSocket, dbName) dsn = fmt.Sprintf("%s:%s@unix(%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", dbUser, dbPassword, dbSocket, dbName)
} else { } else {
dsn = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", dbUser, dbPassword, dbHost, dbPort, dbName) dsn = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", dbUser, dbPassword, dbHost, dbPort, dbName)
} }
db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{}) db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
// Connect to a SQLite database. // Connect to a SQLite database.