pg - PostgreSQL connector for Tarantool
- Tarantool 1.6.5+ with header files (tarantool && tarantool-dev packages)
- PostgreSQL 8.1+ header files (libpq-dev package)
Clone repository and then build it using CMake:
git clone https://github.com/tarantool/pg.git
cd pg && cmake . -DCMAKE_BUILD_TYPE=RelWithDebugInfo
make
make install
You can also use LuaRocks:
luarocks install https://raw.githubusercontent.com/tarantool/pg/master/pg-scm-1.rockspec --local
See tarantool/rocks for LuaRocks configuration details.
local pg = require('pg')
local conn = pg.connect({host = localhost, user = 'user', pass = 'pass', db = 'db'})
local tuples = conn:execute("SELECT ? AS a, 'xx' AS b", 42))
conn:begin()
conn:execute("INSERT INTO test VALUES(1, 2, 3)")
conn:commit()
Connect to a database.
Options:
host
- a hostname to connectport
- a port numner to connectuser
- usernamepass
orpassword
- a passworddb
- a database nameconnstring
(mutual exclusive with host, port, user, pass, db) - PostgreSQL connection stringraise
= false - raise an exceptions instead of returning nil, reason in all API functions
Returns:
connection ~= nil
on successnil, reason
on error ifraise
is falseerror(reason)
on error ifraise
is true
Execute a statement with arguments in the current transaction.
Returns:
{ { column1 = value, column2 = value }, ... }
on successnil, reason
on error ifraise
is falseerror(reason)
on error ifraise
is true
Example:
tarantool> conn:execute("SELECT ? AS a, 'xx' AS b", 42)
---
- - a: 42
b: xx
...
Begin a transaction.
Returns: true
Commit current transaction.
Returns: true
Rollback current transaction.
Returns: true
Execute a dummy statement to check that connection is alive.
Returns:
true
on successfalse
on failure