npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@journeyapps/wa-sqlite

v1.1.1

Published

[![wa-sqlite CI](https://github.com/powersync-ja/wa-sqlite/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/powersync-ja/wa-sqlite/actions/workflows/ci.yml?branch=master)

Downloads

4,533

Readme

wa-sqlite CI

Beta

This package is currently in a beta release.

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.

If you do want to build - e.g. you want to change build flags, use a specific EMSDK version, or modify wa-sqlite itself - 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/.

PowerSync instructions

Note as per above that this is known to compile under Debian.

Make sure to have OpenSSL@3 installed on your system.

Development has been done using VSCode's development container feature.

git clone [this repo]
make -B

PowerSync Core

The PowerSync Rust SQLite extension is used both statically and dynamically in this package. The static core binary is downloaded in the Makefile during compilation. The dynamic WASM files are not commited to this repository's dist folder, instead the WASM files are downloaded as a postinstall script.

Update the powersync-version file in order to update the PowerSync core version.

Usage with PowerSync

This fork of WA-SQLite can be used with PowerSync either statically or dynamically. See the demo worker for usage.

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 '@journeyapps/wa-sqlite/dist/wa-sqlite.mjs';
  import * as SQLite from '@journeyapps/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:

| Parameter | Purpose | Values | Default | |----|----|----|----| | build | Emscripten build type | default, asyncify, jspi | default | | config | select VFS | MemoryVFS, MemoryAsyncVFS, IDBBatchAtomicVFS, IDBMirrorVFS, AccessHandlePoolVFS, OPFSAdaptiveVFS, OPFSAnyContextVFS, OPFSCoopSyncVFS, OPFSPermutedVFS | uses SQLite internal memory | | reset | clear 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.