初始化实现

This commit is contained in:
Yun
2026-06-06 02:09:22 +08:00
commit 83c727372a
10 changed files with 670 additions and 0 deletions
@@ -0,0 +1,29 @@
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
}