switch to mysql driver, separate pgx logic, handle no-change migration

This commit is contained in:
2024-11-23 17:08:03 +01:00
parent 21a9683bf1
commit 198bceb9ba
5 changed files with 36 additions and 26 deletions
+31
View File
@@ -0,0 +1,31 @@
package db
import (
"database/sql"
"log/slog"
"time"
_ "github.com/go-sql-driver/mysql"
)
const maxOpenDbConn = 10
const maxIdleDbConn = 5
const maxDbLifetime = time.Minute * 5
func NewMySQL(dataSource string) (*sql.DB, error) {
d, err := sql.Open("mysql", dataSource)
if err != nil {
slog.Error("error connecting to database", "error", err)
}
d.SetMaxOpenConns(maxOpenDbConn)
d.SetMaxIdleConns(maxIdleDbConn)
d.SetConnMaxLifetime(maxDbLifetime)
if err := d.Ping(); err != nil {
slog.Error("error pinging database", "error", err)
return nil, err
}
return d, nil
}