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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@snomiao/keyv-sqlite

v5.0.4

Published

Multi-driver SQLite storage adapter for Keyv with support for node:sqlite, bun:sqlite, and better-sqlite3.

Readme

SQLite store for keyv

A high-performance SQLite cache store for keyv with support for multiple SQLite drivers.

Note: This is a fork of @resolid/keyv-sqlite by @huijiewei with multi-driver support for node:sqlite, bun:sqlite, and better-sqlite3. See comparison below.

Installation

npm i @snomiao/keyv-sqlite

Usage

Basic Usage

import KeyvSqlite from '@snomiao/keyv-sqlite';  // or: import { KeyvSqlite } from '...'
import Keyv from "keyv";

// Simple file path (recommended), note: WAL mode is enabled by default
const store = new KeyvSqlite('./cache.db');
const keyv = new Keyv({ store });

// In-memory cache
const store = new KeyvSqlite(':memory:');
const keyv = new Keyv({ store });

// Default (in-memory)
const store = new KeyvSqlite();
const keyv = new Keyv({ store });

Helper Function

import { createKeyv } from '@snomiao/keyv-sqlite';

// Simple file path
const keyv = createKeyv('./cache.db');

// With options
const keyv = createKeyv({ uri: 'cache.sqlite' });

With Options

const store = new KeyvSqlite({
  uri: './cache.db',
  table: 'my_cache',        // Custom table name
  wal: true,                // WAL mode (default: true)
  busyTimeout: 10000,       // Busy timeout in ms
  iterationLimit: 100       // Iterator batch size
});

Features

  • Synchronous API: No await needed for instantiation
  • Auto-detection: Automatically uses the best available SQLite driver
  • Multiple drivers: Supports node:sqlite, bun:sqlite, and better-sqlite3
  • Cross-runtime: Works in Node.js, Bun, and Deno
  • WAL mode: Enabled by default for better performance
  • 100% test coverage and production ready

API

Constructor

new KeyvSqlite(options?: KeyvSqliteOptions | string)

Pass a string for the file path, or an options object for advanced configuration.

Methods

All methods are async to match the Keyv interface:

  • get(key) - Get a value
  • getMany(keys) - Get multiple values
  • set(key, value, ttl?) - Set a value with optional TTL
  • delete(key) - Delete a value
  • deleteMany(keys) - Delete multiple values
  • clear() - Clear all values
  • iterator(namespace?) - Async iterator over entries
  • disconnect() - Close the database connection

Advanced Usage

Using Specific Drivers

// Use node:sqlite explicitly
const store = new KeyvSqlite({
  uri: 'cache.sqlite',
  driver: 'node:sqlite'
});

// Use bun:sqlite explicitly
const store = new KeyvSqlite({
  uri: 'cache.sqlite',
  driver: 'bun:sqlite'
});

// Use better-sqlite3 explicitly
const store = new KeyvSqlite({
  uri: 'cache.sqlite',
  driver: 'better-sqlite3'
});

Custom Driver Module

import Database from 'better-sqlite3';

const store = new KeyvSqlite({
  uri: 'cache.sqlite',
  driver: Database  // Pass the driver constructor directly
});

Supported Drivers

The library auto-detects and uses the best available driver for your runtime:

Native Drivers (First-class support)

  • node:sqlite - Built into Node.js 22.5.0+ (requires --experimental-sqlite flag)
  • bun:sqlite - Built into Bun runtime

NPM Packages

  • better-sqlite3 - Requires installation: npm install better-sqlite3

Native drivers are pre-loaded at module initialization using top-level await, making the constructor fully synchronous.

Requirements

  • Node.js 18+ (Node.js 22.5.0+ for native node:sqlite support)
  • Or Bun runtime for native bun:sqlite support
  • Or better-sqlite3 package installed

Configuration Options

type KeyvSqliteOptions = {
  uri?: string;              // Database file path (default: ":memory:")
  driver?: DriverType | DriverModule;  // Driver selection (default: "auto")
  table?: string;            // Table name (default: "caches")
  wal?: boolean;             // Enable WAL mode (default: true)
  busyTimeout?: number;      // Busy timeout in ms (default: 5000)
  iterationLimit?: number;   // Iterator batch size (default: 10)
};

Fork Differences

This fork (@snomiao/keyv-sqlite) differs from the original @resolid/keyv-sqlite in the following ways:

| Feature | Original (@resolid) | This Fork (@snomiao) | |---------|---------------------|----------------------| | SQLite drivers | ✅ better-sqlite3 only | ✅ Multi-driver (node:sqlite, bun:sqlite, better-sqlite3) | | Auto-detection | ❌ No | ✅ Yes (picks best driver for runtime) | | Native drivers | ❌ No | ✅ node:sqlite (Node 22.5+), bun:sqlite | | Cross-runtime | ⚠️ Node.js only | ✅ Node.js, Bun, Deno | | WAL mode | ⚠️ Opt-in (off by default) | ✅ Enabled by default | | Driver abstraction | ❌ No | ✅ Yes (sqliteAdapter.ts with top-level await) | | String parameter | ❌ No | ✅ Yes (new KeyvSqlite('./db')) | | Benchmark workflow | ❌ No | ✅ Comprehensive multi-driver benchmarks | | Build tool | tsup | tsdown | | Linter | biome | oxlint + oxfmt |

Key Innovation

The main difference is multi-driver support with automatic runtime detection:

Upstream approach:

import Database from "better-sqlite3";  // ← Hardcoded, must have better-sqlite3

This fork approach:

// Pre-loads native drivers at module initialization (top-level await)
let nodeSqliteDriver = await import("node:sqlite");      // ← Zero dependencies!
let bunSqliteDriver = await import("bun:sqlite");        // ← Zero dependencies!
let betterSqlite3 = await import("better-sqlite3");      // ← Fallback

// Auto-selects best available driver
// OR accepts custom driver: new KeyvSqlite({ driver: MyCustomDriver })

This allows the fork to:

  1. Prefer native drivers (zero dependencies, no compilation)
  2. Fall back gracefully to better-sqlite3 if needed
  3. Accept custom drivers for maximum flexibility
  4. Work across runtimes (Node.js, Bun, Deno) seamlessly

Migration from Original

If migrating from @resolid/keyv-sqlite:

- npm install @resolid/keyv-sqlite
+ npm install @snomiao/keyv-sqlite

The API is backwards compatible. Simply change the package name - your existing code will continue to work!

Optional improvements:

  • Option name change: enableWALModewal (both work)
  • Can now use string parameter: new KeyvSqlite('./db')
  • Will auto-detect best driver (or specify with driver option)

Credits

This fork is based on the excellent work by @huijiewei in keyv-sqlite. The multi-driver support and cross-runtime compatibility were built on top of their solid foundation.

License

MIT.

Thanks

Thanks to JetBrains for the OSS development license.

JetBrain