zitadel/internal/database/database.go
Florian Forster fa9f581d56
chore(v2): move to new org (#3499)
* chore: move to new org

* logging

* fix: org rename caos -> zitadel

Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
2022-04-26 23:01:45 +00:00

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
}