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 tarantool-mysql
cd tarantool-mysql && cmake . -DCMAKE_BUILD_TYPE=RelWithDebugInfo
make
make installYou can also use LuaRocks:
luarocks install https://raw.githubusercontent.com/tarantool/mysql/master/mysql-scm-1.rockspec --localSee tarantool/rocks for LuaRocks configuration details.
local mysql = require('mysql')
local conn = mysql.connect({host = localhost, user = 'user', password = 'password', db = 'db'})
local status, 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- usernamepassword- a passworddb- a database nameraise= false - raise an exceptions instead of returning nil, reason in all API functions
Returns:
connection ~= nilon successnil, reasonon error ifraiseis falseerror(reason)on error ifraiseis true
Execute a statement with arguments in the current transaction.
Returns:
true, { { column1 = value, column2 = value }, ... }, { {column1 = value, ... }, ...}on successnil, reasonon error ifraiseis falseerror(reason)on error ifraiseis true
Example:
tarantool> conn:execute("SELECT ? AS a, 'xx' AS b", 42)
---
- - true
- - 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:
trueon successfalseon failure
mysql.pool_create({host = host, port = port, user = user, password = password, db = db, size = size)
Create a connection pool with count of size established connections.
Options:
host- a hostname to connectport- a port numner to connectuser- usernamepassword- a passworddb- a database nameraise= false - raise an exceptions instead of returning nil, reason in all API functionssize- count of connections in pool
Returns
pool ~=nilon successnil, reasonon error ifraiseis falseerror(reason)on error ifraiseis true
Get a connection from pool. Reset connection before return it. If connection is broken then it will be reestablished. If there is no free connections then calling fiber will sleep until another fiber returns some connection to pool.
Returns:
connection ~= nil
Return a connection to connection pool.
Options
conn- a connection
All calls to connections api will be serialized, so it should to be safe to use one connection from some count of fibers. But you should understand, that you can have some unwanted behavior across db calls, for example if another fiber 'injects' some sql between two your calls.
