app-cloudep-wallet-service/pkg/lib/sql_client/initMySQL.go

31 lines
778 B
Go
Raw Permalink Normal View History

2025-04-16 09:24:54 +00:00
package sql_client
import (
"code.30cm.net/digimon/app-cloudep-wallet-service/internal/config"
"fmt"
"gorm.io/gorm"
)
func NewMySQLClient(conf config.Config) (*gorm.DB, error) {
dbConf := &Config{
User: conf.MySQL.UserName,
Password: conf.MySQL.Password,
Host: conf.MySQL.Host,
Port: conf.MySQL.Port,
Database: conf.MySQL.Database,
MaxIdleConns: conf.MySQL.MaxIdleConns,
MaxOpenConns: conf.MySQL.MaxOpenConns,
ConnMaxLifetime: conf.MySQL.ConnMaxLifetime,
InterpolateParams: true,
}
dbInit := New(dbConf, WithLogLevel(conf.MySQL.LogLevel))
orm, err := dbInit.Conn()
if err != nil {
return nil, fmt.Errorf("failed to initiate db connection pool: %w", err)
}
return orm, nil
}