This SQLite3 extension allows you to evaluate JavaScript expressions using the Duktape library.
- CMake >= 3.16
To build the extension, follow these steps:
- Create a build directory:
mkdir build cd build
- Generate the build files using CMake:
cmake ..
- Build the extension:
make
This will create the libeval_js.so
shared library in the build
directory.
-
Load the extension in SQLite3:
SELECT load_extension('/path/to/libjs_eval_ext.so', 'sqlite3_js_eval_init');
Replace /path/to/libeval_js.so with the actual path to the built libeval_js.so file.
-
Use the eval_js function to evaluate JavaScript expressions:
SELECT eval_js('a * (b + c)', 'a', 2, 'b', 3, 'c', 4) AS result;
This will evaluate the JavaScript expression a * (b + c) with the provided key-value pairs as variables (a = 2, b = 3, c = 4) and return the result (14).
To run the tests, execute the following command in the build directory:
ctest
This will run the test suite and display the results.