sysbench
sysbench copied to clipboard
driver:connect option to provide connection setting directly
refs #348
with this PR, sysbench.sql.driver():connect
can accept connection setting directly, instead of from command line. this increase our flexisibility of writing test, readability (you can easily see which database each connection connects from source code)
below is simplified example usage of our side.
local conn = {}
function thread_init()
-- you should provide either host/port or socket. otherwise raise error
conn.db1 = sysbench.sql.driver():connect({
host = os.getenv('DB1_HOST'),
port = tonumber(os.getenv('DB1_PORT')),
user = os.getenv('DB1_USER'),
password = os.getenv('DB1_PASSWORD'),
db = os.getenv('DB1_DATABASE')
})
conn.db2 = sysbench.sql.driver():connect({
socket = os.getenv('DB2_SOCKET'),
user = os.getenv('DB1_USER'),
password = os.getenv('DB1_PASSWORD'),
db = os.getenv('DB1_DATABASE')
})
end
function event(thread_id)
-- use db1 to fetch data
local data = conn.db1:query('SELECT * FROM table WHERE id = \'' .. thread_id .. '\''):fetch_row()
-- then use it for db2
conn.db2:query('INSERT INTO table2 VALUES(' .. data[1] .. ',' .. data[2] .. ')')
end