substitutefor

software · Q898

Substitutes for sql.js

SQLite compiled to WebAssembly or JavaScript, with in-memory databases and explicit file export.

Suggest a correction

Compare your options

Find a substitute for sql.js

Start with what you need to do. Compare the fit, differences, and sources for each option.

1 option

PGlite

Sourced comparison

Embedding a local SQL database in JavaScript applications and development workflows limited

PGlite → sql.js

Can replace embedded SQL storage when PostgreSQL semantics are wanted; SQLite files, dialect and persistence APIs require migration.

Platforms: Web, JavaScript, TypeScript, Node.js, Bun, Deno · Region: Version, build and integration requirements apply

Sources for this comparison (2)Article revision 1022
How sql.js compares as a replacement

Embedding SQLite queries and database-file inspection in JavaScript applications limited

sql.js → PGlite

Can replace embedded SQL execution when SQLite and explicit file export fit the task; PostgreSQL schema features and storage formats are not interchangeable.

Platforms: Web, JavaScript, WebAssembly, Node.js · Region: Version, build and integration requirements apply

Sources for this comparison (2)Article revision 946

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]

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]

Capabilities & limitations

SQLite file loading and export

supported

Loads database bytes and exports a SQLite file as Uint8Array; saving is application-owned.[1][2]

Embedding SQLite queries and database-file inspection in JavaScript applications · Web, JavaScript, WebAssembly, Node.js · Version, build and integration requirements apply

2 sources · check evidence
https://github.com/sql-js/sql.js/blob/master/README.md

Memory model, WASM loading, export and BigInt limitations

vendor · checked 2026-10-07
https://sql.js.org/documentation/Database.html

Database lifecycle, export pragma reset and custom functions

vendor · checked 2026-10-07

Automatic durable writes

unsupported

The documented default uses an in-memory virtual database and does not persist changes automatically.[1]

Embedding SQLite queries and database-file inspection in JavaScript applications · Web, JavaScript, WebAssembly, Node.js · Version, build and integration requirements apply

1 source · check evidence
https://github.com/sql-js/sql.js/blob/master/README.md

Memory model, WASM loading, export and BigInt limitations

vendor · checked 2026-10-07

Prepared statements

supported

Supports bound values and result iteration; statements must be freed after use.[3]

Embedding SQLite queries and database-file inspection in JavaScript applications · Web, JavaScript, WebAssembly, Node.js · Version, build and integration requirements apply

1 source · check evidence
https://sql.js.org/documentation/Statement.html

Parameter binding, memory cleanup and locking warning

vendor · checked 2026-10-07

Worker API parity

limited

Worker exposes selected message actions rather than the complete direct Database API.[2][4]

Embedding SQLite queries and database-file inspection in JavaScript applications · Web, JavaScript, WebAssembly, Node.js · Version, build and integration requirements apply

2 sources · check evidence
https://github.com/sql-js/sql.js/blob/master/src/worker.js

Supported message actions, IDs and error responses

vendor · checked 2026-10-07
https://sql.js.org/documentation/Database.html

Database lifecycle, export pragma reset and custom functions

vendor · checked 2026-10-07

References

  1. sql.js repository overview

    Memory model, WASM loading, export and BigInt limitations

    vendor · retrieved 2026-10-07
  2. Database API

    Database lifecycle, export pragma reset and custom functions

    vendor · retrieved 2026-10-07
  3. Statement API

    Parameter binding, memory cleanup and locking warning

    vendor · retrieved 2026-10-07
  4. Worker implementation

    Supported message actions, IDs and error responses

    vendor · retrieved 2026-10-07
  5. sql.js license

    MIT terms for sql.js

    vendor · retrieved 2026-10-07
  6. PGlite introduction

    Embedded PostgreSQL and storage options

    vendor · retrieved 2026-10-07

Discussion & disputes

Ask about unclear claims or explain a concern with supporting sources. If you have a specific fix, suggest a correction.

No discussion yet.

Sign in with an active account to join the discussion.

Revision history

Open a revision to read an earlier version of this article.

RevisionTimestampEdit summary
9462026-10-13 14:11:23/* wbeditentity-create-item:0| */ sf:8138a3c1-24b8-4c7d-9522-ec36ad81bf98:v1 | Add sql.js with explicit persistence, statement cleanup, export pragma reset and limited worker API. | attribution: /proposals/8138a3c1-24b8-4c7d-9522-ec36ad81bf98