There was an error while loading. Please reload this page.
1 parent c171596 commit 48d6992Copy full SHA for 48d6992
1 file changed
pgutils/connector.go
@@ -192,3 +192,23 @@ func OpenDB(conn *PostgresqlConnector) *sqlx.DB {
192
sqlDB := sql.OpenDB(conn)
193
return sqlx.NewDb(sqlDB, "postgres")
194
}
195
+
196
+// ConnectDB opens a connection using the connector and verifies it with a ping
197
+func ConnectDB(conn *PostgresqlConnector) (*sqlx.DB, error) {
198
+ db := OpenDB(conn)
199
+ if err := db.Ping(); err != nil {
200
+ db.Close()
201
+ return nil, err
202
+ }
203
+ return db, nil
204
+}
205
206
+// MustConnectDB is like ConnectDB but panics on error
207
+func MustConnectDB(conn *PostgresqlConnector) *sqlx.DB {
208
+ db, err := ConnectDB(conn)
209
+ if err != nil {
210
+ panic(err)
211
212
+ return db
213
214
0 commit comments