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

drawers

v1.0.1

Published

Key streaming schema for leveldb

Downloads

6

Readme

drawers

Basic schema implementation for leveldb databases

Installation

npm install drawers

Usage

Drawers implements a schema for your leveldb database, allowing you to manage our indexes in a declarative way:

    const Schema = require("drawers/schema");

    class Person extends Schema {
        get storage() {
            return {
                index: "byId",

                schema: {
                    id: String,
                    name: String,
                    age: Number,
                    date: Date
                },

                indexes: [{
                    name: "byId",
                    key: "person:$id",
                    value: (values) => values
                }, {
                    name: "byDate",
                    key: "byDate:$date:$id",
                    value: (values) => values.id
                }, {
                    name: "byAge",
                    key: "byAge:$age:$id",
                    value: (values) => values.id
                }]
            };
        }
    }

The above example validates input and introduces a set of helper methods for querying your dataset:

    const run = async () {
        let db = require("drawers/adapter/memdown");

        let values = {
            id: fakeId(),
            name: "Matt",
            age: 36,
            date: new Date("03-19-1979")
        };

        let person = new Person(db());

        // validate input and stores indexes
        await person.store(values);

        // load person from db
        let myPerson = await person.loadById({ id: values.id });

        // schema values have getters
        console.log(myPerson.name);

        // deletes all keys and indexes
        await person.delete();

        // stream key/values stored in the index "byAge"
        // we can query values between keys thanks to "bytewise"
        person.streamByAge({
            start: {
                age: 9
            },
            end: {
                age: 14
            }
        }).on("data", result => {
            console.log(result.key, result.value);
        })
        .on("finish", console.log);

    }

Pagination

Pagination is supported. The last result will be a pagination key, see [./schema_test.js#L323].

        person.streamByAge()
        .limit(5)
        .on("data", result => {
            console.log(result.key, result.value);
        })
        .on("finish", console.log);

Features

Drawers supports a bunch of handy features:

  • Type validation using https://github.com/mvhenten/izza.
  • Declarative indexes
  • Tansform streams for results from indexes
  • Pagination on streams
  • Coerce values from input
  • Stream JSON fragments (for http chunking)
  • Stream utilities for transforming data
  • sublevel indexes

see /fixtures/person.js for schema implemenation see /schema_test.js for tests