Giter Site home page Giter Site logo

little-pouch-db's Introduction

little pouch db

Little pouch database for testing with relational data

var Pouch = require('pouchdb');
var littlePouchDb = require('little-pouch-db');

littlePouchDb( new Pouch('pouch-test') ).then(function(db) {
  return db.allDocs({include_docs: true});
}).then(function(resp) {
  console.log('these are in the db: ', resp);
});

install

$ npm install little-pouch-db

views

Docs are indexed by name and related fields and values.

views.push({
  _id: '_design/name',
  views: {
    'name': {
      map: function (doc) { emit(doc.name); }.toString()
    }
  }
});

// index on user-created metadata
views.push({
  _id: '_design/kv',
  views: {
    'kv': {
      map: function(doc) {
        if (doc.type === 'node') {
          doc.metadata.forEach(function(pair) {
            emit([pair.field, pair.value]);
          });
        }
      }.toString()
    }
  }
});

views.push({
  _id: '_design/valuesForField',
  views: {
    'valuesForField': {
      map: function(doc) {
        if (doc.type === 'node') {
          doc.metadata.forEach(function(pair) {
            pair.value.forEach(function(val) {
              emit(pair.field, {_id: val});
            });
          });
        }
      }.toString()
    }
  }
});

data

Mythological monsters. Three doc types: nodes, fields, values.

Example:

[
  {
    "name": "hobbies",
    "type": "field",
    "_id": "field16555526-010a-11e5-9822-75338ce32d42",
    "_rev": "1-3027acdc2700e3d110d2a49dcb2efed1"
  },
  {
    "name": "luring",
    "type": "value",
    "_id": "value16557c37-010a-11e5-9822-75338ce32d42",
    "_rev": "1-c04235c9caccd2d57b615f411ad80fd5"
  },
  {
    "name": "sphinx",
    "type": "node",
    "metadata": [
      {
        "field": "fielde80fc400-0110-11e5-8938-872c40161038",
        "value": [
          "valuee80feb10-0110-11e5-8938-872c40161038"
        ]
      },
      {
        "field": "fielde80feb11-0110-11e5-8938-872c40161038",
        "value": [
          "valuee80feb12-0110-11e5-8938-872c40161038"
        ]
      },
      {
        "field": "fielde80feb13-0110-11e5-8938-872c40161038",
        "value": [
          "valuee80feb14-0110-11e5-8938-872c40161038"
        ]
      },
      {
        "field": "fielde80feb15-0110-11e5-8938-872c40161038",
        "value": [
          "valuee80feb16-0110-11e5-8938-872c40161038",
          "valuee80feb17-0110-11e5-8938-872c40161038",
          "valuee80feb18-0110-11e5-8938-872c40161038"
        ]
      }
    ],
    "_id": "nodee80feb19-0110-11e5-8938-872c40161038",
    "_rev": "1-883a09ccfe5d7f978914dce3d3773658"
  }
]

little-pouch-db's People

Contributors

nichoth avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.