sql.js SQLite compiled to WebAssembly or JavaScript, with in-memory databases and explicit file export.
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.[1]
Contents Loading the runtime 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.[1]
Database files and saving 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.[2]
Bound queries and cleanup 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.[3]
Moving work off the UI thread 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.[4]
Application-defined functions 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.[2]
Memory and numeric limitations 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.[1]
License and substitution sql.js itself uses MIT terms, while its SQLite foundation is described as public domain. It can be considered alongside PGlite 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.[1] [5] [6]
References sql.js repository overview Memory model, WASM loading, export and BigInt limitations
vendor · retrieved 2026-10-07 Database API Database lifecycle, export pragma reset and custom functions
vendor · retrieved 2026-10-07 Statement API Parameter binding, memory cleanup and locking warning
vendor · retrieved 2026-10-07 Worker implementation Supported message actions, IDs and error responses
vendor · retrieved 2026-10-07 sql.js license MIT terms for sql.js
vendor · retrieved 2026-10-07 PGlite introduction Embedded PostgreSQL and storage options
vendor · retrieved 2026-10-07 Also included: 4 capabilities and 0 substitute relationships. Check substitutes in section 1 and capabilities in section 3.