Installing sqltable for Torch/Lua
‘sqltable’ is a lua wrapper for accessing SQL tables as Lua Tables. SELECT, INSERT, UPDATE and DELETE become metamethods in such a way that no native SQL needs to be written. Some of the documentation and exact details of how to install it are not clear online, so here is a snapshot of what I learnt spending a few hours installing it.
- Install MySQL or your other flavor of SQL for your OS. If you are on CentOS, follow this link
- Once you are done, run
sudo yum install mysql-devel -y
This installs an SQL client on the same machine, which is useful/required to interface or connect SQL with other platforms. This should also place mysql.h file in /usr/include
directory. This is critical to run the next step. If you dont find it, run the locate mysql.h
command to figure out where it exists.
- Before installing ‘sqltable’, a further step is to install luaDBI. For MySQL, install it using
luarocks install luadbi-mysql MYSQL_INCDIR=/usr/include/mysql
If the path for mysql.h is different, use that in MYSQL_INCDIR path. If this doesnt, work and you get an error that libmysqlclient.so is not found, add a path to it by supplying an additional argument:
luarocks install luadbi-mysql MYSQL_INCDIR=/usr/include/mysql MYSQL_LIBDIR=/usr/lib64/mysql
- Finally, we can install sqltable using luarocks:
luarocks install sqltable
- To verify the installation, try the following commands on the Torch shell
sqltable = require 'sqltable'
sql = sqltable.connect({type='MySQL', name='test'})
Assuming you have created a database called test using mysql command line.
NOTE: This procedure was tested to work on CentOS6.7.