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

node-sqlite-map

v0.0.1

Published

A persistent, Map-compatible key-value store for Node.js backed by node:sqlite

Downloads

99

Readme

node-sqlite-map

A persistent Map-compatible API backed by SQLite using Node.js's built-in node:sqlite module. No external database dependencies — just a file (or :memory:).

Requirements

  • Node.js >= 22.5.0 (for node:sqlite)

Installation

npm install node-sqlite-map
# or
pnpm add node-sqlite-map

Quick Start

import { SqliteMap } from "node-sqlite-map"

const map = new SqliteMap("./data.db")

map.set("user:1", { name: "Kyle", role: "admin" })
map.get("user:1") // { name: "Kyle", role: "admin" }
map.has("user:1") // true
map.size // 1

Use :memory: for an in-memory database that does not persist:

const map = new SqliteMap(":memory:")

API

Constructor

new SqliteMap<K extends string, V>(path: string, options?: DatabaseSyncOptions)

| Parameter | Type | Description | | --------- | --------------------- | --------------------------------------------- | | path | string | Path to SQLite database file, or ":memory:" | | options | DatabaseSyncOptions | Optional Node.js DatabaseSync options |

Core Methods

set(key, value): this

Inserts or replaces a key-value pair. Returns this for chaining.

map.set("a", 1).set("b", 2).set("c", 3)

get(key): V | undefined

Returns the value for the key, or undefined if not found.

map.get("a") // 1
map.get("z") // undefined

has(key): boolean

Returns true if the key exists.

map.has("a") // true

delete(key): boolean

Removes the entry. Returns true if it existed, false otherwise.

map.delete("a") // true
map.delete("a") // false

clear(): void

Removes all entries.

map.clear()
map.size // 0

getOrInsert(key, defaultValue): V

Returns the existing value if the key exists, otherwise inserts defaultValue and returns it.

map.getOrInsert("count", 0) // inserts 0 and returns 0
map.getOrInsert("count", 99) // returns 0 (already exists)

getOrInsertComputed(key, callbackFn): V

Like getOrInsert but the default value is computed lazily via a callback — only called if the key is missing.

map.getOrInsertComputed("slug", (key) => key.toLowerCase().replace(" ", "-"))

Iteration

All iteration methods reflect the insertion order of keys.

keys(): IterableIterator<K>

for (const key of map.keys()) console.log(key) // "a", "b", "c"
console.log([...map.keys()]) // ["a", "b", "c"]

values(): IterableIterator<V>

console.log([...map.values()]) // [1, 2, 3]

entries(): IterableIterator<[K, V]>

console.log([...map.entries()]) // [["a", 1], ["b", 2], ["c", 3]]

forEach(callback): void

map.forEach((value, key, map) => {
    console.log(key, value)
})

[Symbol.iterator]()

Makes the map directly iterable — equivalent to entries().

for (const [key, value] of map) {
    console.log(key, value)
}

Properties

size: number

Returns the number of entries.

map.size // 3

Serialization

toJSON(): Record<string, V>

Returns a plain object representation. Called automatically by JSON.stringify.

map.set("x", 1)
map.toJSON() // { x: 1 }
JSON.stringify(map) // '{"x":1}'

[Symbol.toStringTag]: string

Returns "SqliteMap".

Object.prototype.toString.call(map) // "[object SqliteMap]"

Type Parameters

SqliteMap<K extends string, V>

| Parameter | Constraint | Description | | --------- | ---------- | -------------------------------------- | | K | string | Key type — must be a string | | V | any | Value type — must be JSON-serializable |

Values are stored as JSON strings internally, so any JSON-serializable value is supported: objects, arrays, numbers, booleans, strings, null.

Examples

Persistent cache

const cache = new SqliteMap<string, { data: unknown; expiresAt: number }>("./cache.db")

cache.getOrInsertComputed("api:users", () => ({
    data: fetchUsers(),
    expiresAt: Date.now() + 60_000
}))

Counting

const hits = new SqliteMap<string, number>("./hits.db")

hits.getOrInsert("/home", 0)
hits.set("/home", (hits.get("/home") ?? 0) + 1)

Spreading / converting

// To plain object
const obj = sqliteMap.toJSON()

// To native Map
const native = new Map(sqliteMap.entries())

// From array of entries
for (const [k, v] of entries) sqliteMap.set(k, v)

Differences from native Map

| Feature | Map | SqliteMap | | ---------------- | ----------------- | ----------------- | | Persistence | ❌ In-memory only | ✅ File-backed | | Key type | Any | string only | | Value type | Any | JSON-serializable | | Iteration order | Insertion order | Insertion order | | JSON.stringify | {} (empty) | ✅ Full object |

License

This project is licensed under the MIT License - see the LICENSE file for details.

Links & Community

| Resource | URL | | ----------------- | ----------------------------------------------- | | GitHub repository | https://github.com/xcfio/node-sqlite-map | | npm package | https://www.npmjs.com/package/node-sqlite-map | | Homepage | https://github.com/xcfio/node-sqlite-map#readme | | Bug reports | https://github.com/xcfio/node-sqlite-map/issues |

Discord

Join the community on Discord for help, and discussion:

https://discord.gg/FaCCaFM74Q


Made with ❤️ by xcfio