amp

ampersand-model-pouchdb-mixin

A mixin for extending ampersand-model with pouchdb persistance.

Showing:

Popularity

Downloads/wk

2

GitHub Stars

2

Maintenance

Last Commit

7yrs ago

Contributors

0

Package

Dependencies

2

Size (min+gzip)

74.0KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

ampersand-model-pouchdb-mixin

install

npm install ampersand-model-pouchdb-mixin

example


var _ = require('underscore');
var AmpersandCollection = require('ampersand-collection');
var AmpersandModel = require('ampersand-model');
var AmpersandPouchModelMixin = require('ampersand-model-pouchdb-mixin');
var AmpersandPouchCollectionMixin = require('ampersand-collection-pouchdb-mixin');
var AmpersandUnderscoreMixin = require('ampersand-collection-underscore-mixin');

var Model = AmpersandModel.extend(AmpersandPouchModelMixin, {
  pouch: {
    database: 'mydb'
  },
  props: {
    firstName: 'string',
    lastName: 'string'
  }
});

module.exports = AmpersandCollection.extend(AmpersandPouchCollectionMixin, AmpersandUnderscoreMixin, {
  mainIndex: '_id',
  model: Model,
  pouch: {
    database: 'mydb',
    fetch: 'query',
    options: {
      query: {
        include_docs: true,
        fun: {
          map: function(doc) {
            if (doc) {
              emit(doc, null);
            }
          }
        },
        limit: 10
      },
      changes: {
        include_docs: true,
        filter: function(doc) {
          return doc;
        }
      }
    }
  },
  parse: function(result) {
    // only return actual docs
    return _.pluck(result.rows, 'doc');
  }
});

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100