pg: config struct for connecting

pull/1682/head
Istvan 2019-08-20 10:08:06 +02:00 committed by Alexander Medvednikov
parent 33e730b3fa
commit dee411149e
1 changed files with 9 additions and 3 deletions

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 {