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:
parent
33e730b3fa
commit
dee411149e
12
vlib/pg/pg.v
12
vlib/pg/pg.v
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user