Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

WebAssembly SQLite with support for browser storage extensions

License

NotificationsYou must be signed in to change notification settings

rhashimoto/wa-sqlite

Repository files navigation

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 ishere.

Try the demo or runbenchmarks with a modern desktop web browser. More information is available in theFAQ,discussion forums, andAPI 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 withmake arguments, and the helper projectsqwab 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 sureemcc works.
  • git clone git@github.com:rhashimoto/wa-sqlite.git
  • cd wa-sqlite
  • yarn install
  • make

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

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:

importSQLiteESMFactoryfrom'wa-sqlite/dist/wa-sqlite.mjs';import*asSQLitefrom'wa-sqlite';asyncfunctionhello(){constmodule=awaitSQLiteESMFactory();constsqlite3=SQLite.Factory(module);constdb=awaitsqlite3.open_v2('myDB');awaitsqlite3.exec(db,`SELECT 'Hello, world!'`,(row,columns)=>{console.log(row);});awaitsqlite3.close(db);}hello();

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

Theimplementation ofsqlite3.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:

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 sponsorsFleet Device Management andReflect.Existing licensees may continue under the GPLv3 or switch to the new license.


[8]ページ先頭

©2009-2025 Movatter.jp