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

db-engine

v0.5.1

Published

a database building toolkit

Downloads

5

Readme

DB Engine

A conceptual database engine toolkit, including a query language, indexes, and storage.

Concepts

DB Engine is a key/value store, where the value is a JSON object. It has the ability to store, index, and query data.

Querying the Database

There are two methods that DB Engine uses to query the data held by it: Indexes, and Full Table Scans.

Full Table Scans do just what it sounds like, they scan through the whole store, making comparisons. Full Table Scans use the following comparison mechanisms:

  • equals - checks for equality
  • gt - greater than
  • gte - greater than or equal
  • lt - less than
  • lte - less than or equal
  • between - lies in between or equal to

In addition, Indexes allow for faster queries, and are keyed against a single field in the data.

Indexes can expose other query operations for additional types of queries. This allows for expansion of other types of data and operations with the simple addition of an index.

Query Languages

DB Engine at the most basic level uses a tree based query language. Other query languages can be parsed and coerced into this form for consumption, including the built-in query language that is part of DB Engine.

Queries are built in JSON, and are descriptive.

{
  operand: "equals",
  key: "foo",
  value: "bar"
}

In this example, an equality check is done against the value contained in the foo field. If it matches with equality, then the result is returned.

{
  "foo": "bar",
  "baz": [
    1,
    2,
    3
  ]
}

This object would be matched.

Built-in Query Language

In addition, there is a built-in query language that is more semantic.

{
  "foo": "bar"
}

Parses out to:

{
  operand: "equals",
  key: "foo",
  value: "bar"
}

As does:

{
  "foo": {
    equals: "bar"
  }
}

Queries can have complex logic. When a query is using and or or, it allows for boolean logic:

{
  "$and": [
    {
      "$or": [
        {
          "name": {
            "equals": "Main"
          }
        },
        {
          "crime.type": {
            "equals": "Arson"
          }
        }
      ]
    },
    {
      "date": {
        "between": [ '2013-11-30', '2014-01-01' ]
      }
    }
  ]
}

This query finds any object that has a name field of "Main", plus any objects that have a crime.type of "Arson". The results of those are compared to the results of any objects that have a date between "2013-11-30" and "2014-01-01".

This query would parse to:

{
  operand: "$and",
  value: [
    {
      operand: "$or",
      value: [
        {
          operand: "equals",
          key: "name",
          value: "Main"
        },
        {
          operand: "equals",
          key: "crime.type",
          value: "Arson"
        }
      ]
    },
    {
      operand: "between",
      key: "date",
      value: [ '2013-11-30', '2014-01-01' ]
    }
  ]
}