Socket
Book a DemoInstallSign in
Socket

ampersand-model-pouchdb-mixin

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ampersand-model-pouchdb-mixin

A mixin for extending ampersand-model with pouchdb persistance.

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

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');
  }
});

Keywords

model, ampersand, state

FAQs

Package last updated on 02 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts