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

@deltic/key-value

v0.1.2

Published

A key-value store abstraction

Readme

@deltic/key-value

A key-value store abstraction with in-memory and PostgreSQL implementations.

Installation

npm install @deltic/key-value

For the PostgreSQL implementation, also install:

npm install @deltic/async-pg-pool pg

Usage

Interface

All implementations share the KeyValueStore interface:

interface KeyValueStore<Key, Value> {
    persist(key: Key, value: Value): Promise<void>;
    retrieve(key: Key): Promise<Value | undefined>;
    remove(key: Key): Promise<void>;
    clear(): Promise<void>;
}

In-Memory Store

import {KeyValueStoreUsingMemory} from '@deltic/key-value/memory';

const store = new KeyValueStoreUsingMemory<string, {name: string}>();

await store.persist('user-1', {name: 'Alice'});
const value = await store.retrieve('user-1'); // {name: 'Alice'}
await store.remove('user-1');
await store.clear();

PostgreSQL Store

import {KeyValueStoreUsingPg, createKeyValueSchemaQuery} from '@deltic/key-value/pg';
import {AsyncPgPool} from '@deltic/async-pg-pool';

// Create the table
await connection.query(createKeyValueSchemaQuery('user_settings'));

// Use the store
const store = new KeyValueStoreUsingPg<string, {theme: string}>(asyncPool, {
    tableName: 'user_settings',
});

await store.persist('user-1', {theme: 'dark'});
const settings = await store.retrieve('user-1'); // {theme: 'dark'}

Multi-Tenancy

The PostgreSQL implementation supports tenant-scoped storage:

const store = new KeyValueStoreUsingPg<string, Settings, string, TenantId>(asyncPool, {
    tableName: 'tenant_settings',
    tenantContext: tenantIdReader,
    tenantIdConversion: tenantIdConversion,
});

Custom Key Conversion

Transform keys before storage:

const store = new KeyValueStoreUsingPg<UserId, Profile, string>(asyncPool, {
    tableName: 'profiles',
    keyConversion: (userId) => userId.toString(),
});

PostgreSQL with Columns

For cases where you want specific object properties stored as separate database columns (enabling queries and indexes) while preserving the full object as a JSON payload:

import {KeyValueStoreWithColumnsUsingPg} from '@deltic/key-value/pg-with-columns';

type UserKey = {username: string; email: string};
type User = {username: string; email: string; age: number; verified: boolean};

const store = new KeyValueStoreWithColumnsUsingPg<UserKey, User>(
    asyncPool,
    'users',
    ['username', 'email'],   // identity columns (form the unique key)
    ['verified'],            // additional columns to extract from the value
);

await store.persist(
    {username: 'alice', email: '[email protected]'},
    {username: 'alice', email: '[email protected]', age: 30, verified: true},
);

API Reference

KeyValueStore<Key, Value> (interface)

| Method | Description | |--------|-------------| | persist(key, value) | Stores a key-value pair (upserts on conflict) | | retrieve(key) | Returns the value or undefined if not found | | remove(key) | Deletes a key-value pair | | clear() | Removes all entries |

createKeyValueSchemaQuery(tableName, ifNotExists?)

Returns a CREATE TABLE SQL string for the standard key-value schema with tenant_id, key, and value columns.

License

ISC