SQLite for macOS
v3.53.4macOSSQLite 3.53.4 for native Node.js addons and Electron on macOS, precompiled for arm64 and x64, macOS 11 or later as @crossbind/port-sqlite3-darwin.
npm install @crossbind/port-sqlite3-darwin@betaInstall
The addons and their loader land in dist; the Node.js playbook has the whole flow.
Usage
The examples the WebAssembly page runs, as macOS compiles them: the same headers and the same calls. They are checked on the WebAssembly build.
Insert and query with prepared statements
The calls behind most SQLite code: sqlite3_prepare_v2, sqlite3_bind_text, sqlite3_step and sqlite3_column_*. Values go in as bound parameters, so the apostrophe in "parser's" is data, not SQL.
3.53.4 3 2: write the README 3: fix the parser's bug
Apply a batch in one transaction
BEGIN, one prepared upsert (ON CONFLICT DO UPDATE) reset and re-bound for every row, then COMMIT. A row that breaks a CHECK constraint makes the wrapper ROLLBACK, which undoes the rows before it as well.
10000 rows applied alice 13333, bob 13330, carol 13331 rolled back: CHECK constraint failed: total >= 0 alice 13333, bob 13330, carol 13331
Query JSON documents with SQL
Keep JSON as it arrives and ask questions in SQL: ->> reads a field, json_each turns an array into rows, and json_group_object and json_group_array build JSON answers.
{"ada":13.75,"linus":15.0}
{"pen":12,"pad":3,"ink":1}
["ada","linus"]Search text with FTS4
A full-text index with CREATE VIRTUAL TABLE … USING fts4, queried with MATCH and cut into snippet()s. Stemming, phrases, prefixes, NOT and NEAR come with it. This build has FTS3 and FTS4 but not FTS5.
parse -> libcurl [parses] and normalizes URLs exactly like the… | [Parsing] XML with expat "signing request" -> …key, a certificate [signing] [request] and a self… brows* -> SQLite in the [browser] parser NOT expat -> curl URL [parser] tag NEAR/2 text -> …start tag, end [tag] and [text] run as…
Save a database to bytes and open it again
sqlite3_serialize copies a database out as the bytes of its file, and sqlite3_deserialize opens such bytes as a database: the way to download, upload or cache a whole database. The copy is then listed with sqlite_schema and pragma_table_info.
8192 B, starts with "SQLite format 3" readings(sensor TEXT, celsius REAL): 3 rows
What is different on macOS
crossbind build -p darwinlinks one.nodeaddon per architecture intodist, next to a loader,dist/<name>.native.cjs, thatrequireandimportboth load. A plaincrossbind buildskips it.await initNative()once, then call the classes: calls are synchronous, and no Worker is involved.- The library is linked into the addon statically; only libraries that ship with macOS stay dynamic.
- There is no
m.FS: the C++ reads real paths, and data such asGDAL_DATAorproj.dbis copied todist/data. - The build runs on a Mac with Xcode's command line tools and needs Docker for the SWIG bridges.
worker_threadsare not supported yet.
Other platforms
- SQLite overview: the apps, every platform's setup and the packages.
- SQLite for WebAssembly: browsers, Node.js and edge runtimes.
- SQLite for Android: React Native apps on Android.
- SQLite for iOS: React Native apps on iOS.
- SQLite for Linux: native Node.js addons on Linux.
- SQLite for Windows: native Node.js addons on Windows.
- SQLite for WASI: command-line programs under wasmtime.
Facts on this page come from the port manifests in the repository and from what npm served on beta when the site was built. See the Libraries guide for the full consumer flow.