Skip to content

Commit

Permalink
Update MySQL TimeZone
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmmdriz committed Jun 25, 2024
1 parent bff05eb commit e49fe61
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion drivers/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"e-complaint-api/drivers/mysql/seeder"
"e-complaint-api/entities"
"fmt"
"time"

"gorm.io/driver/mysql"
"gorm.io/gorm"
Expand All @@ -19,12 +20,19 @@ type Config struct {
}

func ConnectDB(config Config) *gorm.DB {
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Asia/Jakarta",
loc, err := time.LoadLocation("Asia/Jakarta")
if err != nil {
panic(err)
}

// Creating the DSN with loc parameter
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=%s",
config.DB_USERNAME,
config.DB_PASSWORD,
config.DB_HOST,
config.DB_PORT,
config.DB_NAME,
loc.String(),
)
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
Expand Down

0 comments on commit e49fe61

Please sign in to comment.