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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@webreflection/sql.js

v0.3.3

Published

An ESM re-packaged sql.js with embedded sqlite.wasm as buffer

Downloads

107

Readme

@webreflection/sql.js

An ESM re-packaged sql.js with embedded sqlite.wasm as buffer:

  • same initSqlJs API and functionalities
  • zero need to host the sqlite-wasm.wasm file a part
  • works already in both main or workers
// works in both main and workers
import initSqlJs from 'https://esm.run/@webreflection/sql.js';

const SQL = await initSqlJs();

const db = new SQL.Database();

db.run(`
CREATE TABLE hello (a int, b char);
INSERT INTO hello VALUES (0, 'hello');
INSERT INTO hello VALUES (1, 'world');
`); // Run the query without returning anything

// Prepare an sql statement
const stmt = db.prepare("SELECT * FROM hello WHERE a=:aval AND b=:bval");

// Bind values to the parameters and fetch the results of the query
const result = stmt.getAsObject({':aval' : 1, ':bval' : 'world'});
console.log(result); // Will print {a:1, b:'world'}

db.close();

@webreflection/sql.js/persistent

Based on IndexedDB, this export provides an extend of the SQL.Database class with an additional delete() and save() methods plus a smart constructor that does the following:

import Database from 'https://esm.run/@webreflection/sql.js/persistent';

const db = new Database(
  // the persistent name of such db
  'data.db',
  // an optional buffer to use when
  // no such name exists in the storage
  someOptionalBufferToInit
);

// create a table only if not present
db.run('CREATE TABLE IF NOT EXISTS hello (a int, b char)');

// do anything you would do with an SQLite DB

// save it, optionally awaiting for it
await db.save();

// close it or keep going
db.close();

The constructor signature allows to create or reuse a previously stored DB, providing eventually a DB that existed already and that's exported as buffer or Uint8Array.

When previously stored, the next time that DB would be used instead of such provided initial DB, simplifying the orchestration between new user or freed cache VS some data to crawl anyway for such user.

It is also possible to db.delete() (optionally awaitable) some file ti be sure the storage is clean and to migrate from a version of a DB to another one.

Like it is for the default export of this module, /persistent works in both main thread and workers.

Warnings ⚠️

The last db.save() operation will define the state of the database.

This export works if you are running it on a single Page (PWA, Electron, etc.) but if you are running the same thing in multiple tabs last .save() will last, not the others.

To solve this issue I've provided also the following shared variant.

@webreflection/sql.js/shared

This export is an async version of the persistent Database that bootstraps a SharedWorker so that multiple tabs can read and/or write to the same db where db.save() invokes will be queue to avoid concurrent saves within the worker.

The prepare statement is currently missing due to the nature of the cursor and the needed orchestration behind but I am not excluding its availability in the future.

Almost all other methods are supported and provide an async version of the official API.