Skip to content

Commit f18086c

Browse files
authored
db.pg: allow postgres connection using service definitions (#19288)
1 parent 621cb6d commit f18086c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

vlib/db/pg/pg.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ fn C.PQfinish(conn &C.PGconn)
144144
// a connection error when something goes wrong
145145
pub fn connect(config Config) !DB {
146146
conninfo := 'host=${config.host} port=${config.port} user=${config.user} dbname=${config.dbname} password=${config.password}'
147+
148+
return connect_with_conninfo(conninfo)!
149+
}
150+
151+
// connect_with_conninfo makes a new connection to the database server using
152+
// the `conninfo` connection string, returning
153+
// a connection error when something goes wrong
154+
pub fn connect_with_conninfo(conninfo string) !DB {
147155
conn := C.PQconnectdb(&char(conninfo.str))
148156
if conn == 0 {
149157
return error('libpq memory allocation error')

0 commit comments

Comments
 (0)