mysql - MySQL connector for Tarantool
- Tarantool 1.6.5+ with header files (tarantool && tarantool-dev packages)
- MySQL 5.1 header files (libmysqlclient-dev package)
Clone repository and then build it using CMake:
git clone https://github.com/tarantool/mysql.git
cd mysql && cmake . -DCMAKE_BUILD_TYPE=RelWithDebugInfo
make
make install
You can also use LuaRocks:
luarocks install https://raw.githubusercontent.com/tarantool/mysql/master/mysql-scm-1.rockspec --local
See tarantool/rocks for LuaRocks configuration details.
local mysql = require('mysql')
local conn = mysql.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 nameraise
= 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 }, ... }, nrows
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
- 1
...
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