SQLite for Android
v3.53.4AndroidSQLite 3.53.4 for React Native apps on Android, precompiled for arm64-v8a devices and the x86_64 emulator as @crossbind/port-sqlite3-android.
npm install @crossbind/port-sqlite3-android@betaInstall
The whole flow, including Expo, is in the React Native playbook.
Usage
The examples the WebAssembly page runs, as Android 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 Android
- The React Native plugin compiles your headers with the library inside Gradle's native build, so
npm run androidbuilds everything. - Named imports from
./native/<header>.hwork as on the web:await initNative()once, then call the classes. - There is no
m.FSand no/memfs: files live in the app's own storage, and your C++ takes their paths. - No Worker and no COOP or COEP:
runtime: 'mt'uses pthreads directly.
Other platforms
- SQLite overview: the apps, every platform's setup and the packages.
- SQLite for WebAssembly: browsers, Node.js and edge runtimes.
- SQLite for iOS: React Native apps on iOS.
- 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.