mirror of
https://github.com/get-drexa/drive.git
synced 2025-11-30 21:41:39 +00:00
fix: registration endpoint and db auto close issue
This commit is contained in:
@@ -2,6 +2,7 @@ package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
"github.com/uptrace/bun/dialect/pgdialect"
|
||||
@@ -10,6 +11,17 @@ import (
|
||||
|
||||
func NewFromPostgres(url string) *bun.DB {
|
||||
sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(url)))
|
||||
|
||||
// Configure connection pool to prevent "database closed" errors
|
||||
// SetMaxOpenConns sets the maximum number of open connections to the database
|
||||
sqldb.SetMaxOpenConns(25)
|
||||
// SetMaxIdleConns sets the maximum number of connections in the idle connection pool
|
||||
sqldb.SetMaxIdleConns(5)
|
||||
// SetConnMaxLifetime sets the maximum amount of time a connection may be reused
|
||||
sqldb.SetConnMaxLifetime(5 * time.Minute)
|
||||
// SetConnMaxIdleTime sets the maximum amount of time a connection may be idle
|
||||
sqldb.SetConnMaxIdleTime(10 * time.Minute)
|
||||
|
||||
db := bun.NewDB(sqldb, pgdialect.New())
|
||||
return db
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user