1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

pg: config struct for connecting

This commit is contained in:
Istvan 2019-08-20 10:08:06 +02:00 committed by Alexander Medvednikov
parent 33e730b3fa
commit dee411149e

View File

@ -24,14 +24,20 @@ import const (
struct C.PGResult { }
struct Config {
pub:
host string
user string
password string
}
fn C.PQconnectdb(a byteptr) *C.PGconn
fn C.PQerrorMessage(voidptr) byteptr
fn C.PQgetvalue(voidptr, int, int) byteptr
fn C.PQstatus(voidptr) int
pub fn connect(dbname, user string) DB {
//conninfo := 'host=localhost user=$user dbname=$dbname'
conninfo := 'host=127.0.0.1 user=$user dbname=$dbname'
pub fn connect(config pg.Config) DB {
conninfo := 'host=$config.host user=$config.user dbname=$config.dbname'
conn:=C.PQconnectdb(conninfo.str)
status := C.PQstatus(conn)
if status != CONNECTION_OK {