SQLite WASM HTTP VFS Backend

1.2.0 · active · verified Wed Apr 22

sqlite-wasm-http provides an HTTP Virtual File System (VFS) backend for the official SQLite WASM distribution, enabling direct querying of remote SQLite databases over HTTP. It is designed to be a robust solution for browser and Node.js environments (Node.js 18+ required for full functionality) and supports features like multiple concurrent connections with shared caching (requiring `SharedArrayBuffer` and COOP/COEP headers) or a simplified fall-back without it. The library is currently at v1.2.0 and appears to have a semi-regular release cadence, with updates often tied to new official SQLite WASM builds or bug fixes. A key differentiator is its focus on the official SQLite WASM distribution, aiming to be an industry reference, and its support for shared cache across workers, offering performance benefits over similar solutions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the HTTP VFS backend and connect to a remote MBTiles database. It then executes a simple query to list tables and count entries at a specific zoom level, showcasing basic database interaction and proper resource cleanup.

import { createSQLiteThread, createHttpBackend } from 'sqlite-wasm-http';

async function runRemoteQuery() {
  const remoteURL = 'https://velivole.b-cdn.net/maptiler-osm-2017-07-03-v3.6.1-europe.mbtiles';
  // createHttpBackend will autodetect if you can use SharedArrayBuffer or not
  const httpBackend = createHttpBackend({
    maxPageSize: 4096,    // This is the current default SQLite page size
    timeout: 10000,       // 10s
    cacheSize: 4096       // 4 MB (corresponds to 4096 pages of 1KB each for default 1024 page_size)
  });

  // Multiple DB workers can be created, all sharing the same backend cache
  const db = await createSQLiteThread({ httpBackend });

  try {
    const results = await db.exec({
      sql: 'SELECT name FROM sqlite_master WHERE type=\'table\';'
    });
    console.log('Tables:', results.results[0].row);

    const countResult = await db.exec({
      sql: 'SELECT count(*) FROM tiles WHERE zoom_level = ?;',
      bind: [1]
    });
    console.log('Tiles at zoom 1:', countResult.results[0].row);
  } finally {
    db.close();
  }
}

runRemoteQuery().catch(console.error);

view raw JSON →