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

level-join

v0.0.0

Published

join leveldb documents based on common nested values

Downloads

5

Readme

level-join

join leveldb documents based on common nested values

build status

example

Given this dataset with commit and output rows:

[
  { "type": "commit", "id": 444, "hash": "6eba8e6a2927a5d8b748d422ad7e64b977ab4f94", "time": 1374904364802 },
  { "type": "output", "job": 444, "data": "beep ", "time": 1374904288007 },
  { "type": "output", "job": 444, "data": "boop.", "time": 1374904289854 },
  { "type": "commit", "id": 555, "hash": "5c825a710662cab0b8abb37132cae19d0dcf00cb", "time": 1374904278950 },
  { "type": "output", "job": 555, "data": "hello ", "time": 1374904366509 },
  { "type": "output", "job": 555, "data": "world!", "time": 1374904367169 }
]

we can populate the database with db.batch() and then join each output's job property with a matching commit id property. This is like a foreign key in an SQL database, except that it can be arbitrarily nested.

var sub = require('level-sublevel');
var level = require('level');
var through = require('through');
var shasum = require('shasum');

var db = sub(level('/tmp/testdb', { valueEncoding: 'json' }));
var join = require('level-join')(db);

db.batch(require('./data.json').map(function (row) {
    var key = shasum(row);
    return { type: 'put', key: key, value: row };
}));

join.add('commit', [ 'id' ], [ 'type', 'commit' ]);
join.add('output', [ 'job' ], [ 'type', 'output' ]);

join.pipe(through(function (pair) {
    console.log(pair.commit.hash, pair.output.data);
}));

For each pairing of commit and output objects, the commit hash and output data get printed:

5c825a710662cab0b8abb37132cae19d0dcf00cb hello 
6eba8e6a2927a5d8b748d422ad7e64b977ab4f94 boop.
5c825a710662cab0b8abb37132cae19d0dcf00cb world!
6eba8e6a2927a5d8b748d422ad7e64b977ab4f94 beep 

Note that the results are not grouped or sorted. A grouping and sorting module could be of use here.

methods

var levelJoin = require('level-join')

var join = levelJoin(db)

Create a new join instance from a [sublevel](https://npmjs.org/package/level-sublevel]-capable leveldb handle db.

join is an object-mode readable stream that outputs pair objects with keys for each of the names that have been added with join.add() and values of the matching documents.

join.add(name, joinPath, filterPath)

Add name to the join using the value at the pathway array joinPath and filtering results by the filterPath array that will be passed through directly to level-search.

install

With npm do:

npm install level-join

license

MIT