Installation
cr-sqlite
is distributed as a run time loadable extension (opens in a new tab) for SQLite and can be used with any language that has SQLite bindings.
Acquiring the extension
Pre-built binaries - You can download a pre-built binary for your platform from GitHub releases (opens in a new tab).
Building from source - You may also build from source by cloning the cr-sqlite repository (opens in a new tab) and following the instructions in the readme.
Packages
- NodeJS & Deno - see docs/nodejs
- Browser/WASM - see docs/wasm
Loading the extension
Once you've acquired the extension you'll need to load it into your SQLite connection. This is done by calling the sqlite3_load_extension
function with the path to the extension and, optionally, the entrypoint of the extension.
If you downloaded a prebuilt binary it is recommended to rename it to crsqlite.[dll/so/dylib]
. This follows SQLite's expected naming conventions for extensions.
If you do not rename it, you will need to pass sqlite3_crsqlite_init
as an argument to sqlite3_load_extension
(opens in a new tab).
You must load the cr-sqlite extension into a connection before interacting with any CRRs on that connection.
Examples:
import sqlite3
conn = sqlite3.connect(db_file)
c.enable_load_extension(True)
conn.load_extension('path/to/crsqlite')
Closing Connections
You should call SELECT crsql_finalize();
before closing the database connection. This allows the extension to perform some cleanup before database shutdown. Failing to do so is not a critical error, but it may cause exceptions to be thrown when the connection is closed. The JS connection wrapper in the crsqlite-wasm
package automatically does this for you when closing connections.
Example:
conn.exec('SELECT crsql_finalize();');
conn.close();