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

hyperdb

v4.1.2

Published

P2P Indexable Database

Downloads

865

Readme

hyperdb

Database built for P2P and local indexing

npm install hyperdb

Usage

First generate your definition with the builder. The definition defines the schemas and collections you wanna use.

// TODO (see ./example here for now)

Then boot your db. You can use the same definition for a fully local db and a P2P one.

const HyperDB = require('hyperdb')

// first choose your engine
const db = HyperDB.rocks('./my-rocks.db', require('./my-definition'))

It is that simple.

API

db = Hyperdb.bee(bee, definition, [options])

Make a db backed by Hyperbee. P2P!

db = Hyperdb.rocks(bee, definition, [options])

Make a db backed by RocksDB. Local only!

queryStream = db.find(collectionOrIndex, query, [options])

Query the database. collectionOrIndex is the identifier you defined in your builder.

The query looks like this

{
  gt: { ... },
  gte: { ... },
  lt: { ...},
  lte: { ...}
}

And options include

{
  limit, // how many max?
  reverse // reverse stream?
}

See the basic tests for an easy example on how queries look like.

The queryStream is a streamx readable stream that yields the documents you search for.

A query is always running on a snapshot, meaning any inserts/deletes you do while this is running will not impact the query stream itself.

all = await queryStream.toArray()

Stream helper to simply get all the remaining entries in the stream.

one = await queryStream.one()

Stream helper to simply get the last entry in the stream.

doc = await db.findOne(collectionOrIndex, query, [options])

Alias for await find(...).one()

doc = await db.get(collection, query)

Get a document from a collection

{ count } = await db.stats(collectionOrIndex)

Get stats, about a collection or index with stats enabled.

await db.insert(collection, doc)

Insert a document into a collection. NOTE: you have to flush the db later for this to be persisted.

await db.delete(collection, query)

Delete a document from a collection. NOTE: you have to flush the db later for this to be persisted.

bool = db.updated([collection], [query])

Returns a boolean indicating if this database was updated. Pass a collection and doc query to know if a specific record was updated.

await db.flush()

Flush all changes to the db

db.reload()

Reload the internal snapshot. Clears the memory state.

db = db.snapshot()

Make a readonly snapshot of the database. All reads/streams are locked in time on a snapshot from the time you call the snapshot method.

db = db.transaction()

Make a writable snapshot of the database. All reads/streams are locked in time on a snapshot from the time you call the snapshot method. When you flush this one, it updates the main instance also.

await db.close()

Close the database. You have to close any snapshots you use also.

License

Apache-2.0