You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var dbConn *bun.DB
// GetDB gets the pointer to the database.
func GetDB() *bun.DB {
return dbConn
}
// Close the DB connection
func Close() {
if dbConn != nil {
dbConn.Close()
}
}
// Connect to the database
func Connect() error {
if dbConn != nil {
return nil
}
cfg := config.GetConfig()
sslMode := "disable"
if cfg.DatabaseSSLMode {
sslMode = "require"
}
dsn := fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s",
cfg.DatabaseUser, cfg.DatabasePassword, cfg.DatabaseHost, cfg.DatabasePort, cfg.DatabaseName, sslMode)
sqlDB := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(dsn)))
dbConn = bun.NewDB(sqlDB, pgdialect.New())
maxOpenConns := 2 * runtime.GOMAXPROCS(0)
dbConn.SetMaxIdleConns(maxOpenConns)
dbConn.SetMaxOpenConns(maxOpenConns)
_, err := dbConn.ExecContext(context.Background(), "SELECT 1")
if err != nil {
sentry.CaptureException(err)
return err
}
return nil
}
and when I use this connection I am getting this error:
sql: database is closed
My question is if the pgdriver handles someway the reconnection to the Database Server, perhaps there is a parameter to pass to the connection, because the Database is not down and if I restart the container it works
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this issue will be closed.
I am using a global connection like this:
and when I use this connection I am getting this error:
My question is if the pgdriver handles someway the reconnection to the Database Server, perhaps there is a parameter to pass to the connection, because the Database is not down and if I restart the container it works
The text was updated successfully, but these errors were encountered: