sql.js runs SQLite in the browser or Node.js via WebAssembly. You can create in-memory databases, import existing .sqlite files, and export results as typed arrays.
Overview
sql.js is a JavaScript SQL database built by compiling SQLite to WebAssembly with Emscripten. It lets you instantiate a relational database entirely in JavaScript, run CREATE and SELECT statements, and work with prepared statements, custom functions, and aggregates in process memory.
By default the active database lives in memory, so changes are not persisted unless you export the file bytes. You can load an existing SQLite file from user input, fetch, or disk in Node.js, and write the database back out as a Uint8Array when finished.
Browser use loads a separate .wasm asset or an inline build that embeds the binary. Node.js installs from npm and can read and write database files on disk after export. A Web Worker variant offloads heavy queries from the main thread, and builds include production, debug, and browser-targeted flavors.
The documentation notes that native SQLite bindings are preferable for Electron or Node when you need direct file access and better performance; sql.js fits interactive browser demos, client-side analytics, and portable SQLite experimentation without a server database.
Key features
- WebAssembly SQLite engine
- In-memory database by default
- Import and export SQLite file bytes
- Prepared statements and binding
- Custom SQL functions and aggregates
- Web Worker build option
- Inline single-file wasm bundle
- Node.js npm package
Use cases
- Browser-side SQL prototyping
- Client-side SQLite file inspection
- Teaching SQL without a server
- Offline demo interpreters
- Node scripts with wasm SQLite