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

pouchdb-model

v0.4.0

Published

[![Build Status](https://travis-ci.org/ewnd9/pouchdb-model.svg?branch=master)](https://travis-ci.org/ewnd9/pouchdb-model) [![Coverage Status](https://coveralls.io/repos/github/ewnd9/pouchdb-model/badge.svg?branch=master)](https://coveralls.io/github/ewnd9

Downloads

9

Readme

pouchdb-model

Build Status Coverage Status

Convenient Wrapper for PouchDB

Install

$ npm install --save pouchdb-model

Examples

import PouchDB from 'pouchdb';
import init from 'pouchdb-model/dist/init';

// if you don't use migrations, you could omit this import
import MigratePlugin from 'pouchdb-migrate';
PouchDB.plugin(MigratePlugin);

const File = {
  createId: ({ name }) => name,
  migrations: [
    function(doc) {
      if (doc.foo) {
        return;
      }

      doc.foo = true;
      return [doc];
    }
  ],
  indexes: [
    {
      name: 'updatedAtIndex',
      fn: function(doc) {
        emit(doc.updatedAt + '$' + doc._id);
      }
    }
  ]
};

async function main(models) {
  const { File } = await init(models, name => new PouchDB(name.toLowerCase()))

  const docA = await File.put({ name: 'user-a' });
  /*
  { name: 'user-a',
    _id: 'user-a',
    updatedAt: '2016-11-03T19:35:19.869Z',
    _rev: '1-1ccfb26dd920cbf8ac11c965efac73d9' }
  */
  const docB = await File.put({ name: 'user-b' });
  /*
  { name: 'user-b',
    _id: 'user-b',
    updatedAt: '2016-11-03T19:36:16.827Z',
    _rev: '1-7ce9e72b2c2ed18fd1753e0c6627e6b0' }
  */

  const docs = await File.findAll();
  /*
  [ { name: 'user-a',
    updatedAt: '2016-11-03T19:38:44.765Z',
    _id: 'user-a',
    _rev: '1-722dd9fc99ef1f04334544bc01e0639a',
    _key: 'user-a' },
  { name: 'user-b',
    updatedAt: '2016-11-03T19:38:44.766Z',
    _id: 'user-b',
    _rev: '1-b3b0f835f60044a68faf04e80a91ced7',
    _key: 'user-b' } ]
  */

  const docsByUpdateAt = await File.findByIndex('updatedAtIndex', { descending: true });
  /*
  [ { name: 'user-b',
    updatedAt: '2016-11-03T19:45:27.729Z',
    _id: 'user-b',
    _rev: '1-ab63623e330d68e060bc2f93ddab0279',
    _key: '2016-11-03T19:39:27.403Z$user-b' },
  { name: 'user-a',
    updatedAt: '2016-11-03T19:45:27.728Z',
    _id: 'user-a',
    _rev: '1-c6da589a48e47402198e145ace61155f',
    _key: '2016-11-03T19:39:27.403Z$user-a' } ]
  */
}

try {
  main({ File });
} catch (e) {
  console.error(e.stack || e);
}

Methods

#createId(data: Object)

Returns the _id field in data or new id generated by a function provided in an initializer

#findById(id: String)

#findOne(data: Object)

#findAll(options: Object?)

#findByIndex(options: Object?)

#put(data: Object)

#update(data: Object)

Overwrites the previous object if existed with a correct _rev or insert a new doc

#bulk(data: Object[])

Returns an array of the same length containing corresponding doc (has _id and _rev) or error (has error, name, status and, in case of validation error - err)

#sync(db: PouchDB | String, options: Object?, notify: Function)

Changelog

  • v0.4.0
    • createdAt property

Related

License

MIT © ewnd9