pg: add binding for PQfinish (close) (#6435)

pull/6439/head
Leonardo Cecchi 2020-09-21 01:47:37 +02:00 committed by GitHub
parent e429a77de2
commit 21c5ff681b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -37,6 +37,7 @@ fn C.PQnfields(voidptr) int
fn C.PQexec(voidptr) voidptr fn C.PQexec(voidptr) voidptr
fn C.PQexecParams(voidptr) voidptr fn C.PQexecParams(voidptr) voidptr
fn C.PQclear(voidptr) voidptr fn C.PQclear(voidptr) voidptr
fn C.PQfinish(voidptr)
pub fn connect(config Config) ?DB { pub fn connect(config Config) ?DB {
conninfo := 'host=$config.host port=$config.port user=$config.user dbname=$config.dbname password=$config.password' conninfo := 'host=$config.host port=$config.port user=$config.user dbname=$config.dbname password=$config.password'
@ -67,6 +68,11 @@ fn res_to_rows(res voidptr) []Row {
return rows return rows
} }
// close frees the underlaying resource allocated by the database connection
pub fn (db DB) close() {
C.PQfinish(db.conn)
}
pub fn (db DB) q_int(query string) int { pub fn (db DB) q_int(query string) int {
rows := db.exec(query) rows := db.exec(query)
if rows.len == 0 { if rows.len == 0 {