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

ORM fixes

This commit is contained in:
Alexander Medvednikov
2019-12-05 22:31:56 +03:00
parent 79b26b1654
commit 71c0c4803f
3 changed files with 39 additions and 42 deletions

View File

@@ -19,10 +19,10 @@ struct C.PGResult { }
pub struct Config {
pub:
host string
user string
password string
dbname string
host string
user string
password string
dbname string
}
fn C.PQconnectdb(a byteptr) &C.PGconn
@@ -31,17 +31,17 @@ fn C.PQgetvalue(voidptr, int, int) byteptr
fn C.PQstatus(voidptr) int
fn C.PQntuples(voidptr) int
fn C.PQnfields(voidptr) int
fn C.PQexec(voidptr) int
fn C.PQexecParams(voidptr) int
fn C.PQexec(voidptr) voidptr
fn C.PQexecParams(voidptr) voidptr
pub fn connect(config pg.Config) DB {
pub fn connect(config pg.Config) ?DB {
conninfo := 'host=$config.host user=$config.user dbname=$config.dbname'
conn:=C.PQconnectdb(conninfo.str)
conn := C.PQconnectdb(conninfo.str)
status := C.PQstatus(conn)
println("status=$status")
if status != C.CONNECTION_OK {
error_msg := C.PQerrorMessage(conn)
eprintln('Connection to a PG database failed: ' + string(error_msg))
exit(1)
return error ('Connection to a PG database failed: ' + string(error_msg))
}
return DB {conn: conn}
}