Skip to content

Instantly share code, notes, and snippets.

@will
Created July 15, 2015 23:33
Show Gist options
  • Save will/9a99d15fca18e521c38f to your computer and use it in GitHub Desktop.
Save will/9a99d15fca18e521c38f to your computer and use it in GitHub Desktop.
@[Link(ldflags: "-lpq -I`pg_config --includedir` -L`pg_config --libdir`")]
lib LibPQ
fun connect = PQconnectdb(conninfo : UInt8*) : Void*
fun exec = PQexec(conn : Void*, query : UInt8*) : Void*
fun getvalue = PQgetvalue(res : Void*, row : Int32, column : Int32) : UInt8*
end
conn = LibPQ.connect("postgres:///")
res = LibPQ.exec(conn, "select 'Hello it is ' || now()")
String.new(LibPQ.getvalue(res, 0, 0)) #=> "Hello it is 2015-07-15 16:30:44.396092-07"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment