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 🙏

© 2024 – Pkg Stats / Ryan Hefner

doubledb

v2.2.0

Published

An on disk database that indexes everything for fast querying.

Downloads

18

Readme

doubledb

GitHub code size in bytes GitHub package.json version GitHub js-semistandard-style

An on disk database that indexes everything for fast querying.

Installation

npm install --save doubledb

Features

  • [x] read
  • [x] insert
  • [x] replace
  • [x] patch
  • [x] remove
  • [x] find
  • [x] filter
  • [ ] query

Usage

import createDoubledb from 'doubledb';
const doubledb = createDoubledb('./data');

doubledb.insert({
  id: undefined, // defaults to uuid, must be unique
  firstName: 'Joe',
  lastName: 'Bloggs',
  stats: {
    wins: 10,
    loses: 5
  },
  skills: ['cooking', 'running']
});

doubledb.get(record.id);
doubledb.find('firstName', 'Joe');
doubledb.find('stats.wins', 10);
doubledb.find('skills', 'cooking');
doubledb.find('firstName', v => v.startsWith('J'), { skip: 20, gt: 'J', lt: 'K' });
doubledb.filter('firstName', 'Joe');
doubledb.filter('firstName', v => v.startsWith('J'));
doubledb.filter('firstName', v => v.startsWith('J'), { limit: 10, skip: 20, gt: 'J', lt: 'K' });
doubledb.replace(record.id, { firstName: 'Joe', lastName: 'Bloggs' });
doubledb.patch(record.id, { firstName: 'Bob' });
doubledb.remove(record.id);

.get(id)

Get a single record by it's .id property.

If a record is found, the whole record will be returned. If no record is found, undefined will be returned.

.find(field, value, { skip })

Quickly find a single record by any field (use.dot.notation.for.nested.properties) and it's exact value.

If multiple records exist, a skip option can be provided to ignore the first number of finds.

If a record is found, the whole record will be returned. If no record is found, undefined will be returned.

.find(field, matcherFunction: (value: string) => boolean), { limit, skip, gt, lt, gte, lte })

Slow find a single record by any field and test against a matcherFunction.

If multiple records exist:

  • a skip option can be provided to ignore the first number of finds.
  • a limit option can be provided to stop after number of finds.

Find using a matcherFunction will work without a gt and lt, but the indexing will be pretty useless, as it will need to scan every single record.

You should provide a gt and/or lt to let the indexer know where to begin/end.

For example, the query below will scan every first name from A all the way to Z

doubledb.find('firstName', v => v.startsWith('Jo'))

Let's tell it to start from Jo.

doubledb.find('firstName', v => v.startsWith('Jo'), { gt: 'Jo' })

This will skip all indexes lower than Jo. However if it can't find any records, it will keep checking, even if the firstName is Zelda

So we should help the indexer by giving it a lt.

doubledb.find('firstName', v => v.startsWith('Jo'), { gt: 'Jo', lt: 'K' })

Let's look at some more examples:

doubledb.find('favouriteNumber', v => v > 5 && v < 10, { gt: 5, lt: 10 })
doubledb.find('firstName', v => ['Dave', 'Peter'].includes(v), { gt: 'Dave', lte: 'Peter' })

If a record is found, the whole record will be returned. If no record is found, undefined will be returned.

.filter(field, matcherFunction: (value: string) => boolean), { limit, skip, gt, lt, gte, lte })

This works the exact same as .find but will return an array.

If records are found, an array will be returned containing every complete found record. If no records are found, an empty array will be returned.

.replace(key, object)

Completely replace a key with a new object, losing all previous fields in the record.

.patch(key, object)

Merge the new object in with the existing record.

For example, if the following record exists:

{
  "id": "1",
  "firstName": "Joe",
  "lastName": "Bloggs"
}

And you run the following .patch.

doubledb.patch('1', { fullName: 'Joe Bloggs' })

The final record will be:

{
  "id": "1",
  "firstName": "Joe",
  "lastName": "Bloggs",
  "fullName": "Joe Bloggs"
}

.remove(key)

Completely remove the key and it's value from the database.

Proposed Query

This hasn't been implemented yet, but it's something I'd like and think could work.

const record = doubledb.query({
  location: 'London',
  category: 'b',

  $or: {
    firstName: {
      $eq: 'Joe',
    },
    firstName: {
      $eq: 'joe',
    }
  }
})