{"schemaVersion":"1.0","record":{"label":"sql.js","description":"SQLite compiled to WebAssembly or JavaScript, with in-memory databases and explicit file export.","aliases":["sqljs"],"kind":"software","website":"https://sql.js.org/","overview":"sql.js compiles SQLite for JavaScript environments, normally through WebAssembly. It can create or load a SQLite database into memory and query it in the browser. Changes are not automatically written back to a file or durable browser store; an application must export and save the database when persistence is required.","license":"MIT wrapper; SQLite is public domain","lifecycle":"active","example":false,"features":[{"name":"SQLite file loading and export","status":"supported","detail":"Loads database bytes and exports a SQLite file as Uint8Array; saving is application-owned.","useCase":"Embedding SQLite queries and database-file inspection in JavaScript applications","platforms":["Web","JavaScript","WebAssembly","Node.js"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://github.com/sql-js/sql.js/blob/master/README.md","locator":"Memory model, WASM loading, export and BigInt limitations","retrievedAt":"2026-10-07T23:43:41Z","kind":"vendor"},{"url":"https://sql.js.org/documentation/Database.html","locator":"Database lifecycle, export pragma reset and custom functions","retrievedAt":"2026-10-07T23:44:55Z","kind":"vendor"}]},{"name":"Automatic durable writes","status":"unsupported","detail":"The documented default uses an in-memory virtual database and does not persist changes automatically.","useCase":"Embedding SQLite queries and database-file inspection in JavaScript applications","platforms":["Web","JavaScript","WebAssembly","Node.js"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://github.com/sql-js/sql.js/blob/master/README.md","locator":"Memory model, WASM loading, export and BigInt limitations","retrievedAt":"2026-10-07T23:43:41Z","kind":"vendor"}]},{"name":"Prepared statements","status":"supported","detail":"Supports bound values and result iteration; statements must be freed after use.","useCase":"Embedding SQLite queries and database-file inspection in JavaScript applications","platforms":["Web","JavaScript","WebAssembly","Node.js"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://sql.js.org/documentation/Statement.html","locator":"Parameter binding, memory cleanup and locking warning","retrievedAt":"2026-10-07T23:44:02Z","kind":"vendor"}]},{"name":"Worker API parity","status":"limited","detail":"Worker exposes selected message actions rather than the complete direct Database API.","useCase":"Embedding SQLite queries and database-file inspection in JavaScript applications","platforms":["Web","JavaScript","WebAssembly","Node.js"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://github.com/sql-js/sql.js/blob/master/src/worker.js","locator":"Supported message actions, IDs and error responses","retrievedAt":"2026-10-07T23:44:55Z","kind":"vendor"},{"url":"https://sql.js.org/documentation/Database.html","locator":"Database lifecycle, export pragma reset and custom functions","retrievedAt":"2026-10-07T23:44:55Z","kind":"vendor"}]}],"alternatives":[],"slug":"sql-js","draftAlternatives":[{"targetSlug":"pglite","status":"limited","detail":"Can replace embedded SQL execution when SQLite and explicit file export fit the task; PostgreSQL schema features and storage formats are not interchangeable.","useCase":"Embedding SQLite queries and database-file inspection in JavaScript applications","platforms":["Web","JavaScript","WebAssembly","Node.js"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://github.com/sql-js/sql.js/blob/master/README.md","locator":"Memory model, WASM loading, export and BigInt limitations","retrievedAt":"2026-10-07T23:43:41Z","kind":"vendor"},{"url":"https://pglite.dev/docs/about","locator":"Embedded PostgreSQL and storage options","retrievedAt":"2026-10-07T23:43:41Z","kind":"vendor"}]}],"evidence":[{"url":"https://github.com/sql-js/sql.js/blob/master/README.md","locator":"Memory model, WASM loading, export and BigInt limitations","retrievedAt":"2026-10-07T23:43:41Z","kind":"vendor"},{"url":"https://sql.js.org/documentation/Database.html","locator":"Database lifecycle, export pragma reset and custom functions","retrievedAt":"2026-10-07T23:44:55Z","kind":"vendor"},{"url":"https://sql.js.org/documentation/Statement.html","locator":"Parameter binding, memory cleanup and locking warning","retrievedAt":"2026-10-07T23:44:02Z","kind":"vendor"},{"url":"https://github.com/sql-js/sql.js/blob/master/src/worker.js","locator":"Supported message actions, IDs and error responses","retrievedAt":"2026-10-07T23:44:55Z","kind":"vendor"},{"url":"https://github.com/sql-js/sql.js/blob/master/LICENSE","locator":"MIT terms for sql.js","retrievedAt":"2026-10-07T23:43:48Z","kind":"vendor"},{"url":"https://pglite.dev/docs/about","locator":"Embedded PostgreSQL and storage options","retrievedAt":"2026-10-07T23:43:41Z","kind":"vendor"}],"document":{"version":1,"references":[{"url":"https://github.com/sql-js/sql.js/blob/master/README.md","locator":"Memory model, WASM loading, export and BigInt limitations","retrievedAt":"2026-10-07T23:43:41Z","id":"readme","title":"sql.js repository overview","kind":"vendor"},{"url":"https://sql.js.org/documentation/Database.html","locator":"Database lifecycle, export pragma reset and custom functions","retrievedAt":"2026-10-07T23:44:55Z","id":"database","title":"Database API","kind":"vendor"},{"url":"https://sql.js.org/documentation/Statement.html","locator":"Parameter binding, memory cleanup and locking warning","retrievedAt":"2026-10-07T23:44:02Z","id":"statement","title":"Statement API","kind":"vendor"},{"url":"https://github.com/sql-js/sql.js/blob/master/src/worker.js","locator":"Supported message actions, IDs and error responses","retrievedAt":"2026-10-07T23:44:55Z","id":"worker","title":"Worker implementation","kind":"vendor"},{"url":"https://github.com/sql-js/sql.js/blob/master/LICENSE","locator":"MIT terms for sql.js","retrievedAt":"2026-10-07T23:43:48Z","id":"license","title":"sql.js license","kind":"vendor"},{"url":"https://pglite.dev/docs/about","locator":"Embedded PostgreSQL and storage options","retrievedAt":"2026-10-07T23:43:41Z","id":"pglite","title":"PGlite introduction","kind":"vendor"}],"overviewCitations":["readme"],"licenseCitations":["license","readme"],"sections":[{"id":"loading","heading":"Loading the runtime","paragraphs":[{"id":"loading-detail","content":[{"text":"The usual WebAssembly build needs both a JavaScript loader and a matching WASM asset. Initialization is asynchronous, and locateFile tells the loader where to obtain the binary when it is not at the expected location. Bundlers must preserve that asset route. An imported JavaScript module alone does not demonstrate that the database engine can initialize after deployment."}],"citations":["readme"]}]},{"id":"files","heading":"Database files and saving","paragraphs":[{"id":"files-detail","content":[{"text":"The database constructor accepts SQLite file bytes. Export returns a Uint8Array that the application can save separately. The API documents an important side effect: export closes and reopens the database, resetting pragmas to their default values. Persistence code must account for connection settings after export rather than treating it as an entirely passive snapshot operation."}],"citations":["database"]}]},{"id":"statements","heading":"Bound queries and cleanup","paragraphs":[{"id":"statements-detail","content":[{"text":"Prepared statements support named and positional parameters and can be reused with different values. They must be freed when finished; the documentation warns that neglected statements can retain memory and cause later table-drop operations to report a lock. Closing the database also makes its statements unusable. This lifecycle is important for generated code that repeatedly reruns queries in a component or interactive editor."}],"citations":["statement"]}]},{"id":"workers","heading":"Moving work off the UI thread","paragraphs":[{"id":"workers-detail","content":[{"text":"The inspected worker implementation accepts messages for opening a database, executing SQL, iterating rows, obtaining the modified-row count, exporting and closing. Responses carry request IDs, and errors are returned through a message path. This is a narrower interface than direct access to every Database method. A client must coordinate requests and completion rather than treating a posted message as an already available result."}],"citations":["worker"]}]},{"id":"extensions","heading":"Application-defined functions","paragraphs":[{"id":"extensions-detail","content":[{"text":"The direct Database API can register JavaScript scalar and aggregate functions for use in SQL. These are runtime registrations, so their presence in a running application should not be confused with ordinary rows stored in an exported file. Applications using them need to initialize the behavior as part of opening their database workflow. No custom function or database was executed for this article."}],"citations":["database"]}]},{"id":"limits","heading":"Memory and numeric limitations","paragraphs":[{"id":"limits-detail","content":[{"text":"The documented model loads the database into memory rather than operating directly on a native disk file. That makes full database size relevant to browser resource use. BigInt support is also asymmetric in the inspected README: retrieving values can be enabled, while binding BigInt inputs is not supported. Those limitations should be checked against application datasets and identifiers before adopting the library."}],"citations":["readme"]}]},{"id":"terms","heading":"License and substitution","paragraphs":[{"id":"terms-detail","content":[{"text":"sql.js itself uses MIT terms, while its SQLite foundation is described as public domain. It can be considered alongside "},{"text":"PGlite","targetSlug":"pglite"},{"text":" for embedded relational queries, especially when the application works with SQLite files. PGlite embeds PostgreSQL and offers a different persistence model. Switching requires checking SQL dialect, data types, file formats and application APIs; this is not a drop-in engine replacement or a tested migration."}],"citations":["license","readme","pglite"]}]}]},"id":"Q898","revision":946,"updatedAt":"2026-10-13T14:11:23Z","sourceUrl":"https://substitutefor.net/entities/Q898?revision=946"}}