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

orbit-pouch-store

v1.0.0-alpha

Published

An OrbitDB docstore that uses PouchDB for indexing.

Downloads

4

Readme

OrbitPouchStore

stability npm version js-standard-style build status test coverage greenkeeper

An OrbitDB store that uses PouchDB for indexing, allowing you to perform flexible mango queries. It extends orbit-db-docstore.

Why?

OrbitDB is a distributed database that stores records as IPFS blocks so that they can be 1) de-duplicated 2) replicated with peers. You can get and share OrbitDB stores by sharing their address, and you can create subsets of your data that peer from users that have the same blocks, even if those blocks aren't part of the same subset or even of the same originating data.

However, OrbitDB's default stores provide only rudimentary indexing, limiting the queries you can make of your data. So, I created a store that used PouchDB for indexing.

OrbitPouchStore is an OrbitDB store that uses a PouchDB instance to index its oplog. That allows you to perform mango queries and map/reduce queries, among other neat things.

I hope you find it useful!

Install

Install using npm:

npm i -S orbit-pouch-store

Now you can use it with OrbitDB:

// 1. add pouch as a store type
const OrbitPouchStore = require('orbit-pouch-store')
OrbitDB.addType('pouch', OrbitPouchStore)

// 2. once you have an orbitdb instance, create the store
const pouch = await orbitdb.create('my-app', 'pouch', options)

// 3. do the thing!
let result = await pouch.put({ greetings: 'hello world' })
let doc = await pouch.get(result.id)
console.log(doc.greetings)
> hello world

Usage

Table of Contents

OrbitPouchStore

Extends OrbitDocStore

OrbitPouchStore - an OrbitDB store indexed by PouchDB

Generally, you will not instantiate this class directly unless you are extending it. Instead, you'll probably use it like this:

// when your app starts:
OrbitDB.addType(OrbitPouchStore.type, OrbitPouchStore)
// then, once you have an orbitdb instance:
let pouch = orbitdb.create(dbName, 'pouch')

Parameters

  • ipfs IPFS An instance of an IPFS node.
  • id String Name of the store, ex: 'blog' or 'test'
  • address Object Address for the store's IPFS feed. Optional.
  • options Object Options object passed through to OrbitDocStore. (optional, default {})

all

Retrieves all documents in the database.

await store.all()
// [{ _id: '...', _rev: '...', ...}, ...]

Returns Array

find

Perform a mango query.

Parameters

Returns Array An array of the documents that matched the query.

query

Performs a map/reduce query.

Parameters

Returns Array

get

Retrieve a document by ID. Without an ID, defaults to retrieving all documents.

Get a single doc:

await store.get(id)
> { _id: '...', _rev: '...', name: 'Mario' }

Get all docs:

await store.get()
> [{ _id: '...', _rev: '...', name: 'Mario' }, ...]

Parameters

  • id String The ID of the document to retrieve.

Returns (Object | Array)

del

Deletes the document with the given ID.

await store.del(id)
> { ok: true }

Parameters

  • id String The '_id' value of the document to delete.

stop

Stop the store and close its resources.

store.stop().then(() => {
  // store has been closed
})

db

Getter for the PouchDB instance used by the index.

store.db

Returns PouchDB

Index

Static getter that returns the class of index used by this store.

OrbitPouchStore.Index

Returns PouchIndex

type

Returns the canonical name of this store, 'pouch'. Useful if you'd rather not type in a raw string.

OrbitPouchStore.type

Returns String

PouchIndex

[PouchIndex description]

Parameters

  • id String [description]
  • options Object [description] (optional, default {})

get

Retrieve a document by ID. Without an ID, defaults to retrieving all documents.

Parameters

  • id String The ID of the document to retrieve.

Returns (Object | Array)

find

Perform a mango query.

Parameters

Returns Array An array of the documents that matched the query.

query

Performs a map/reduce query.

Parameters

Returns Array

db

Getter for the index's PouchDB instance.

Returns PouchDB

Contributing

This library is experimental. All contributions are welcome: bug reports, feature requests, "why doesn't this work" questions, pull requests for fixes and features, etc. For all of the above, file an issue or submit a pull request.

License

Apache-2.0