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

dev-dbmock

v0.0.1

Published

A basic db mock for development environments

Readme

dev-dbmock

a simple json based db for development environments

The aim of this project is to provide a mock db for local developments. The db is composed of json files which can then be easily inspected for debug. The stored objects can be totally arbitrary with the only restriction that they must have a string property called id. When the object is stored in the db an id is created automatically (in a guid-like format) if not already provided.

install

npm install --save-dev dev-dbmock

or

yarn add --dev dev-dbmock

usage

The first thing you need to do is creating the db like this:

Typescript:

import DbMock, { DbMockConfig, DbMockTableConfig } from 'dev-dbmock';

const config: DbMockConfig = { path: 'db/data' };
const { addTable } = await DbMock(config);

Javascript:

import DbMock from 'dev-dbmock';

const config = { path: 'db/data' };
const { addTable } = await DbMock(config);

The only config options are:

  • path (required): the path of the folder were you want to create your db files
  • jsonFormatter (optional): a function that gets an object and returns a string with the json representation. The default one is: (o: any): string => JSON.stringify(o, null, ' ')

Once the db has been created you can start adding a "table" like this:

Typescript:

interface Person {
    id?: string;
    name: string;
}

const tableConfig: DbMockTableConfig = { name: 'persons' };
const { get, put } = await addTable<Person>(DbMockTableConfig);

Javascript:

const tableConfig =  { name: 'persons' };
const { get, put } = await addTable(DbMockTableConfig);

The table config has this properties:

  • name (required): the name of the table. The json file for the table will be called [name].json (what a surprise!)
  • seed (optional): an array of objects to be initially stored in the table. The object must all have an id already.

Once the table is create you can start adding object to it like this:

Typescript:

const newPerson: Person = { name: 'John Lennon' };
const { id } = await put(newPerson);

Javascript:

const newPerson = { name: 'John Lennon' };
const { id } = await put(newPerson); 

If you want to do an update you can just call put with an object with a id.

You can retrieve all the objects in the table like this:

Typescript:

const persons = await get() as Person[];

Javascript:

const persons = await get();

If you want to get just one object instead you can call get passing the id of the object:

Typescript:

const person = await get(id) as Person;

Javascript:

const person = await get(id);

Example

Typescript:

interface Person {
    id?: string;
    name: string;
}
    
const { addTable } = await DbMock({ path: './db/data' });
const { get, put } = await addTable<Person>({ name: 'persons' });
    
// write a record to the db
const newPerson1: Person = { name: 'John Lennon' };
const { id: id1 } = await put(newPerson1);
const person1 = await get(id1) as Person;
console.log(person1); // { id: '[id1]', name: 'John Lennon' }

// write another record
const newPerson2: Person = { name: 'Paul McCartney' };
const { id: id2 } = await put(newPerson2);
const person2 = await get(id2) as Person;
console.log(person2); // { id: '[id2]', name: 'Paul McCartney' }
console.log(await get()); // [{ id: '[id1]', name: 'John Lennon' }, { id: '[id2]', name: 'Paul McCartney' }]

// update a record
await put({ id: id1, name: 'George Harrison' });
await put({ id: id2, name: 'Ringo Starr' });
console.log(await get()); // [{ id: '[id1]', name: 'George Harrison' }, { id: '[id2]', name: 'Ringo Starr' }]

Javascript:

const { addTable } = await DbMock({ path: './db/data' });
const { get, put } = await addTable({ name: 'persons' });
    
// write a record to the db
const newPerson1 = { name: 'John Lennon' };
const { id: id1 } = await put(newPerson1);
const person1 = await get(id1);
console.log(person1); // { id: '[id1]', name: 'John Lennon' }

// write another record
const newPerson2 = { name: 'Paul McCartney' };
const { id: id2 } = await put(newPerson2);
const person2 = await get(id2);
console.log(person2); // { id: '[id2]', name: 'Paul McCartney' }
console.log(await get()); // [{ id: '[id1]', name: 'John Lennon' }, { id: '[id2]', name: 'Paul McCartney' }]

// update a record
await put({ id: id1, name: 'George Harrison' });
await put({ id: id2, name: 'Ringo Starr' });
console.log(await get()); // [{ id: '[id1]', name: 'George Harrison' }, { id: '[id2]', name: 'Ringo Starr' }]