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

collection-storage

v4.0.5

Published

abstraction layer around communication with a collection-based database

Downloads

541

Readme

Collection Storage

Provides an abstraction layer around communication with a collection-based database. This makes switching database choices easier during deployments and testing. Includes wrappers for encryption, compression, caching, and per-record migration.

Currently supports:

  • in-memory storage (available by default)
  • DynamoDB
  • MongoDB
  • PostgreSQL note: Though PostgreSQL is supported, it is not optimised for this type of data storage. If possible, use one of the NoSQL options instead.
  • Redis warning: Redis support is experimental and the database format is likely to change in later versions.
  • SQLite (Node.js 22.13+) note: Though SQLite is supported, it is not optimised for this type of data storage and does not support multiple processes sharing a single database. If possible, use one of the NoSQL options instead.

Install dependency

npm install --save collection-storage

In-memory storage is available by default. To use anything else, you will need to add the corresponding dependency:

npm install --save @collection-storage/dynamodb
npm install --save @collection-storage/mongodb
npm install --save @collection-storage/postgresql
npm install --save @collection-storage/redis
npm install --save @collection-storage/sqlite

And register them either synchronously or asynchronously:

import { CollectionStorage } from 'collection-storage';

CollectionStorage.dynamic([
  ['dynamodb', () => import('@collection-storage/dynamodb')],
  ['mongodb', () => import('@collection-storage/mongodb')],
  ['mongodb+srv', () => import('@collection-storage/mongodb')],
  ['postgresql', () => import('@collection-storage/postgresql')],
  ['redis', () => import('@collection-storage/redis')],
  ['rediss', () => import('@collection-storage/redis')],
  ['sqlite', () => import('@collection-storage/sqlite')],
]);

Usage

import { CollectionStorage } from 'collection-storage';

const db = await CollectionStorage.connect('memory://something');

const simpleCol = db.getCollection('simple');
await simpleCol.add({ id: 10, message: 'Hello' });
const record = await simpleCol.where('id', 10).get();
// record is { id: 10, message: 'Hello' }

const indexedCol = db.getCollection('complex', {
  foo: {},
  bar: { unique: true },
  baz: {},
});
await indexedCol.add(
  { id: 2, foo: 'abc', bar: 'def', baz: 'ghi' },
  { id: 3, foo: 'ABC', bar: 'DEF', baz: 'ghi' },
);

// .values() returns an async generator. This can be passed to (e.g.) Array.fromAsync to collect all values into a list.
const found = await Array.fromAsync(indexedCol.where('baz', 'ghi').values());
// found is [{ id: 2, ... }, { id: 3, ... }]

// Next line throws an exception due to the duplicate key in 'bar'
await indexedCol.add({ id: 4, foo: 'woo', bar: 'def', baz: 'xyz' });

// Binary data
const binaryCol = db.getCollection('my-binary-collection');
await binaryCol.add({ id: 10, someData: Buffer.from('abc', 'utf8') });
const data = await binaryCol.where('id', 10).get();
// data.someData is a Buffer

The unindexed properties of your records do not need to be consistent. In particular, this means that later versions of your application are free to change the unindexed attributes, and both versions can co-exist (see migrate below for details on enabling automatic migrations on a per-record basis).

The MongoDB, PostgreSQL, and SQLite databases support changing indices in any way at a later point. In a later deploy, you can simply create your collection with different indices, and the necessary changes will happen automatically. DynamoDB indices will also be updated automatically but note that this may take some time and will use up capacity on the indices. Redis does not currently support changing or removing existing indices, and will not index existing data if a new index is added.

Connection Strings

See the readme for the database connector you are using for its connection strings. By default, only the in-memory connector is available:

In-memory

memory://<identifier>[?options]

The in-memory database stores data in Maps and Sets. This data is not stored to disk, so when the application closes it is gone. If you specify an identifier, subsequent calls using the same identifier within the same process will access the same database. If you specify no identifier, the database will always be created fresh.

Options

  • simulatedLatency=<milliseconds>: enforces a delay of the given duration whenever data is read or written. This can be used to simulate communication with a remote database to ensure that tests do not contain race conditions.

Documentation

The full documentation can be found here.