Files
mysqlx/example/advanced_options/gorm_advanced_options.go
T

30 lines
751 B
Go
Raw Normal View History

2026-06-06 02:09:22 +08:00
package main
import (
"fmt"
"log"
"time"
"code.yun.ink/pkg/mysqlx"
"gorm.io/gorm/logger"
"gorm.io/gorm/schema"
)
func main() {
client, err := mysqlx.NewDB(
mysqlx.WithDSN("user:password@tcp(127.0.0.1:3306)/testdb?parseTime=true&loc=Local"),
mysqlx.WithLogger(logger.Default.LogMode(logger.Info)),
mysqlx.WithNamingStrategy(schema.NamingStrategy{SingularTable: true}),
mysqlx.WithDisableForeignKeyConstraintWhenMigrating(true),
mysqlx.WithSkipDefaultTransaction(true),
mysqlx.WithConnectionPool(5, 20, 15*time.Minute, time.Hour),
)
if err != nil {
log.Fatalf("failed to create mysqlx client: %v", err)
}
defer client.Close()
fmt.Println("MySQL client created with advanced GORM and connection pool options")
_ = client
}