sql.js
A javascript library to run SQLite on the web.
What is sql.js?
A javascript library to run SQLite on the web.
Overview of sql.js
What it is
sql.js is a JavaScript library that compiles SQLite to WebAssembly using Emscripten, allowing creation and querying of a relational database entirely in the browser. It uses a virtual database file stored in memory and does not persist changes, but supports importing existing SQLite files and exporting the database as a JavaScript typed array (Uint8Array). It also includes contributed math and string extension functions.
Key features
- Runs SQLite in the browser via WebAssembly.
- Create, query, and manage relational databases in memory.
- Import existing SQLite database files and export databases as Uint8Array.
- Supports prepared statements, parameter binding, and custom JavaScript functions and aggregate functions.
- Single-file setup available with
sql-wasm-inline.jsthat embeds the WebAssembly binary. - Can be used in Node.js (requires Node.js 18.3 or newer for Emscripten 6 builds).
Use cases
- Building client-side web applications that need a relational database without a server.
- Offline data processing and analysis in the browser.
- Educational tools for learning SQL.
- Prototyping and testing SQL queries in a browser environment.
- Applications that need to import/export SQLite database files.
Getting started
Install via npm: bash npm install sql.js Basic usage in a browser or Node.js: javascript const initSqlJs = require('sql.js'); const SQL = await initSqlJs({ locateFile: file => `https://sql.js.org/dist/${file}` }); const db = new SQL.Database(); db.run('CREATE TABLE hello (a int, b char);'); db.run('INSERT INTO hello VALUES (0, 'hello');'); const res = db.exec('SELECT * FROM hello'); console.log(res); For a single-file setup without a separate .wasm file, use sql.js/dist/sql-wasm-inline.js.
License and pricing
sql.js is MIT licensed. SQLite is public domain. The project is open source.
Based on the project's public README and repository metadata.