0.1.0 • Published 9 years ago

jimenez-couchdb-endpoints v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 years ago

Build Status

jimenez-couchdb-endpoints

This module helps you to make CRUD operations and queries against couchdb. It depends on another module called jimenez-http-communication which provides http classes for http communication.

##Content ##

Install

$ npm install jimenez-couchdb-endpoints

Run Test

$ npm test

Usage

promiseFactory

It provides the mechanism to get a Promise object from and EndPoint instance.

####Example####

    var promiseFactory = require('jimenez-http-endpoints').promiseFactory;
    
    var factory = promiseFactory(); 
    // see following classes for examples on how to obtain endPoint instances.
    var promise = factory.getPromise(endPoint); 

database

Exposes methods for CRUD operations for a couchdb database.

####Example####

    var database = require('jimenez-http-endpoints').database;
    
    var databaseName = "books";
    var db = database(databaseName);
    var saveEndPoint = db.save(model);
    var updateEndPoint = db.update(model, id, rev);
    var viewEndPoint = db.view(id);
    var delEndPoint = db.delete(id, rev);

tempView

It help us to create temporary couchdb views for queries to a given documents collection.

####Example####

    var tempView = require('jimenez-http-endpoints').tempView;
    
    var databaseName = "books";
    var view = tempView(databaseName);
    
    var mapFunction = function(doc) { 
        if (doc.author) 
            emit(doc.author, doc.pages); 
    };
    
    var reduce = "_sum";
    var group = true;
    
    var endPoint = view.getEndPoint(mapFunction, reduce, group);

view

It help us to create permanent couchdb views for queries to a given documents collection.

####Example####

    var view = require('jimenez-http-endpoints').view;
    
    var databaseName = "books";
    var documentName = "default";
    var v = view(databaseName, documentName);

    v.addView(function(doc) {
      if (doc.author) 
		emit(doc.author, doc.pages); 
    }, 'pageSum', true).
    
    addView(function(doc) { 
      if (doc.author) 
        emit(doc.author, doc.chapters); 
    }, 'chaptersSum', false);
 
    var endPoint = v.getEndPoint();

query

It provides the mechanism to run queries against existing views.

####Example####

    var query = require('jimenez-http-endpoints').query;
    var databaseName = "books";
    var documentName = "default";
    var viewName = "chapterSum";
    
    var q = query(databaseName, documentName, viewName);
    var urlParams = { reduce: false, include_docs = true };
    var endPoint = q.getEndPoint(urlParams); 

Written with StackEdit.

0.1.0

9 years ago

0.0.1

9 years ago