@effect/wa-sqlite

中文文档
0.2.1发布于 2025/08/27TypeScriptES Module零依赖近 30 天下载 3.9万

wa-sqlite CI

原始使用文档
文档目录4 节
  1. Build
  2. API
  3. Demo
  4. License

wa-sqlite CI

wa-sqlite

This is a WebAssembly build of SQLite with support for writing SQLite virtual filesystems completely in Javascript. This allows alternative browser storage options such as IndexedDB and Origin Private File System. Applications can opt to use either a synchronous or asynchronous (using Asyncify or JSPI) SQLite library build (an asynchronous build is required for asynchronous extensions).

IndexedDB and several Origin Private File System virtual file systems are among the examples provided as proof of concept. A table comparing the different VFS classes is here.

Try the demo or run benchmarks with a modern desktop web browser. More information is available in the FAQ, discussion forums, and API reference.

Build

The primary motivation for this project is to enable additions to SQLite with only Javascript. Most developers should be able to use the pre-built artifacts in ./dist. Note that earlier versions of the project only provided pre-built artifacts in the "buildless" branch; that branch will no longer be maintained.

Minor build customization (e.g. changing build defines or flags) can be done with make arguments, and the helper project sqwab can be used to build without a local build environment.

If you do want to build yourself, here are the prerequisites:

  • Building on Debian Linux is known to work, compatibility with other platforms is unknown.
  • yarn - If you use a different package manager (e.g. npm) then file paths in the demo will need adjustment.
  • Emscripten SDK 3.1.61+.
  • curl, make, openssl, sed, tclsh, unzip

Here are the build steps:

  • Make sure emcc works.
  • git clone [email protected]:rhashimoto/wa-sqlite.git
  • cd wa-sqlite
  • yarn install
  • make

The default build produces ES6 modules + WASM, synchronous and asynchronous (using Asyncify and JSPI) in dist/.

API

Javascript wrappers for core SQLITE C API functions (and some others) are provided. Some convenience functions are also provided to reduce boilerplate. Here is sample code to load the library and call the API:

  import SQLiteESMFactory from 'wa-sqlite/dist/wa-sqlite.mjs';
  import * as SQLite from 'wa-sqlite';

  async function hello() {
    const module = await SQLiteESMFactory();
    const sqlite3 = SQLite.Factory(module);
    const db = await sqlite3.open_v2('myDB');
    await sqlite3.exec(db, `SELECT 'Hello, world!'`, (row, columns) => {
      console.log(row);
    });
    await sqlite3.close(db);
  }

  hello();

There is a slightly more complicated example here that also shows how to use a virtual filesystem (VFS) for persistent storage.

The implementation of sqlite3.exec may be of interest to anyone wanting more fine-grained use of SQLite statement objects (e.g. for binding parameters, explicit column datatypes, etc.).

API reference

Demo

To serve the demo directly from the source tree:

  • yarn start
  • Open a browser on http://localhost:8000/demo/?build=asyncify&config=IDBBatchAtomicVFS&reset

The demo page provides access to databases on multiple VFS implementations. Query parameters on the demo page URL can be used to specify the configuration and initial state:

ParameterPurposeValuesDefault
buildEmscripten build typedefault, asyncify, jspidefault
configselect VFSMemoryVFS, MemoryAsyncVFS, IDBBatchAtomicVFS, IDBMirrorVFS, AccessHandlePoolVFS, OPFSAdaptiveVFS, OPFSAnyContextVFS, OPFSCoopSyncVFS, OPFSPermutedVFSuses SQLite internal memory
resetclear persistent storage

For convenience, if any text region is selected in the editor, only that region will be executed. In addition, the editor contents are restored across page reloads using browser localStorage.

License

MIT License as of February 10, 2023, changed by generous sponsors Fleet Device Management and Reflect. Existing licensees may continue under the GPLv3 or switch to the new license.

版本与发布记录

@effect/wa-sqlite 共发布 5 个版本,首次发布于 2024/11/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.1latest2025/08/271.2 年前
0.2.02025/08/271.2 年前
0.1.22024/11/142 年前
0.1.12024/11/142 年前
0.1.02024/11/142 年前

关于 @effect/wa-sqlite 的常见问题

如何安装 @effect/wa-sqlite?

在项目目录运行 npm install @effect/wa-sqlite,或使用 pnpm add / yarn add / bun add。

@effect/wa-sqlite 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@effect/wa-sqlite 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@effect/wa-sqlite 可以商用吗?

@effect/wa-sqlite 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@effect/wa-sqlite 的下载量有多少?

根据 npm 官方下载统计,@effect/wa-sqlite 在 2026/10/13 – 2026/11/11 这 30 天内被下载 38,800 次,日均约 1,293 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@effect/wa-sqlite 还在维护吗?

最新版本 0.2.1 发布于 2025/08/27(1.2 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/11/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。