Lua で SQLCipher (lsqlcipher) を使う
lsqlcipher の Install から使うまで
Install
LuaRocks で install します。
$ luarocks install lsqlcipher
私の今の環境 (macOS) だと LDFLAGS で指定されている path に lcrypto がないので sqlcipher の install に失敗します。
$ luarocks install lsqlcipher Installing https://luarocks.org/lsqlcipher-0.9.5-3.src.rock Missing dependencies for lsqlcipher 0.9.5-3: sqlcipher (not installed) lsqlcipher 0.9.5-3 depends on lua >= 5.1, < 5.5 (5.4-1 provided by VM) lsqlcipher 0.9.5-3 depends on sqlcipher (not installed) Installing https://luarocks.org/sqlcipher-4.4.2-2.rockspec ... configure: error: C compiler cannot create executables See `config.log' for more details Error: Failed installing dependency: https://luarocks.org/sqlcipher-4.4.2-2.rockspec - Build error: Failed building.
やり方は色々だと思いますが、symbolic link を貼りました。
$ ln -s /usr/local/Cellar/openssl@1.1/1.1.1k/lib/libcrypto.dylib /usr/local/lib/ $ ln -s /usr/local/Cellar/openssl@1.1/1.1.1k/include/openssl /usr/local/include/
必ずしも原因が同じとは限らないので、error が出た場合は config.log を見るのが良さそうです。
といっても config.log 消えてると思うので、その場合は Source になっている sqlcipher を自分で build して試してみると良いと思います。
Usage
local sqlite3 = require("lsqlcipher") local db = sqlite3.open("./foo.sqlite") db:key("bar") db:exec [[ CREATE TABLE IF NOT EXISTS baz ( id INTEGER PRIMARY KEY ); ]]
あとは lsqlite3 と一緒です