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

node-pouch

v0.0.3

Published

Easily read/write data to multiple databases using PouchDB.

Downloads

3

Readme

node-pouch

Easily read/write data to multiple databases using PouchDB.

ToDo:

Allow deleting of records.


Usage:

var nodePouch = require("node-pouch");
var pouch = new nodePouch(name, base);
  • name (optional): Database name/link.
  • base (optional): Any base name like folder name to store the database inside that folder. Can be a link too in case of remote database.

Both arguments can be ignored if you want to specify full database name/link everytime in each function.


Methods: (All methods return promises with useful data & errors)

.get(id, name);

pouch.get(id, name);
  • id: Unique record ID.
  • name: Database name/link. Optional if already provided when creating a new instance of the module. Useful if you want to use a different database name/link.

Example:

pouch.get("unique-record-id");

.save(record, name);

pouch.save(record, name);
  • record: A record object like: {_id: "unique-reqcord", name: "Apple", ...}. If _id is not provided, it will be randomly created for you.
  • name: Database name/link. Optional if already provided when creating a new instance of the module. Useful if you want to use a different database name/link.

Example:

pouch.save({
  _id: "unique-record-id",
  name: "Apple",
  description: "Macbooks, iPads, iPhones"
  ...
});

If a record already exists with that _id, then it will be fetched first and all old record object values will also be included for incremental saving. For example, if a record had only name & decription earlier and you now want to save model also, then doing this will be sufficient and your old data will be preserved.

pouch.save({
  _id: "unique-record-id",
  model: "APPLE-001"
  ...
});

.index(fields, name)

pouch.index(fields, name);

Makes search faster if you use indexes.
Indexes are automatically created when you fetch record/records.

  • fields: Fields to combine to make a search index.
  • name: Database name/link. Optional if already provided when creating a new instance of the module. Useful if you want to use a different database name/link.

Example:

pouch.index(["name", "description']);

.record(keyOrObject, name)

pouch.record(keyOrObject, name);
  • keyOrObject: Unique record ID or search object.
  • name: Database name/link. Optional if already provided when creating a new instance of the module. Useful if you want to use a different database name/link.
pouch.record("unique-record-id");

Search indexes are created automatically if search is an object.

pouch.record({name: "Apple", model: "APPLE-001"});

.records(searchObject, name)

pouch.records(searchObject, name);
  • searchObject: Same as the request object provided here: https://pouchdb.com/api.html#query_index
    If selector is not provided in searchObject, then it uses the searchObject itself as selector.
  • name: Database name/link. Optional if already provided when creating a new instance of the module. Useful if you want to use a different database name/link.
pouch.records({name: "Apple", model: "APPLE-001"});
pouch.records({
  selector: {name: "Apple", model: "APPLE-001"},
  fields: ['_id', 'name'],
  sort: ['name']
});