moved mysql connection pool config to openConection func
This commit is contained in:
parent
f472becd89
commit
dd8d043cb8
2 changed files with 5 additions and 4 deletions
|
|
@ -12,6 +12,8 @@ import (
|
||||||
mysqldr "github.com/go-sql-driver/mysql"
|
mysqldr "github.com/go-sql-driver/mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const mysqlMaxConns = 10
|
||||||
|
|
||||||
// DBConnection contains MySQL connection details
|
// DBConnection contains MySQL connection details
|
||||||
type DBConnection struct {
|
type DBConnection struct {
|
||||||
Host string
|
Host string
|
||||||
|
|
@ -83,6 +85,9 @@ func openConnection(connectionString string) (*sql.DB, error) {
|
||||||
return nil, fmt.Errorf("failed to open mysql connection: %w", err)
|
return nil, fmt.Errorf("failed to open mysql connection: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db.SetMaxOpenConns(mysqlMaxConns)
|
||||||
|
db.SetMaxIdleConns(mysqlMaxConns)
|
||||||
|
|
||||||
err = db.Ping()
|
err = db.Ping()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to ping database: %w", err)
|
return nil, fmt.Errorf("failed to ping database: %w", err)
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,6 @@ ORDER BY table_name;
|
||||||
return nil, fmt.Errorf("failed to query %s metadata result: %w", tableType, err)
|
return nil, fmt.Errorf("failed to query %s metadata result: %w", tableType, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxConns = 32
|
|
||||||
db.SetMaxOpenConns(maxConns)
|
|
||||||
db.SetMaxIdleConns(maxConns)
|
|
||||||
|
|
||||||
wg := errgroup.Group{}
|
wg := errgroup.Group{}
|
||||||
for i := 0; i < len(tables); i++ {
|
for i := 0; i < len(tables); i++ {
|
||||||
i := i
|
i := i
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue