mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 19:14:23 +00:00
fa9f581d56
* chore: move to new org * logging * fix: org rename caos -> zitadel Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
27 lines
590 B
Go
27 lines
590 B
Go
package database
|
|
|
|
import (
|
|
"database/sql"
|
|
//sql import
|
|
_ "github.com/lib/pq"
|
|
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
)
|
|
|
|
func Connect(config Config) (*sql.DB, error) {
|
|
client, err := sql.Open("postgres", config.String())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
client.SetMaxOpenConns(int(config.MaxOpenConns))
|
|
client.SetConnMaxLifetime(config.MaxConnLifetime)
|
|
client.SetConnMaxIdleTime(config.MaxConnIdleTime)
|
|
|
|
if err := client.Ping(); err != nil {
|
|
return nil, errors.ThrowPreconditionFailed(err, "DATAB-0pIWD", "Errors.Database.Connection.Failed")
|
|
}
|
|
|
|
return client, nil
|
|
}
|