couchtable

Node.js server module for querying couchdb and returning results to jQuery datatables.

npm install couchtable
14 downloads in the last week
30 downloads in the last month

couchtable

Node.js server module for querying couchdb and returning results to jQuery datatables.

Note: This is an alpha version. Use at your own risk. It has not been heavily tested. Please see TODO.

REQUIREMENTS

INSTALLATION

Step 1) npm install couchtable

Step 2) For the time being, you'll need to manually install your index view. I do plan on creating a generator for the long term. Any json keys you wish to have as column headers will need to be in this view in the format below (title is the name of our json key):

if(doc.title){
  index("title", doc.title, {"store": "yes"});
}

Full Example:

function (doc){

    // doc.type is for filtering doc types. If you use this method of filtering. Leave it.
    if(doc.type){
        index("type", doc.type, {"store": "yes"});
    }


  // Add indexes for the json keys you want to be searchable in the datatables
    if(doc.title){
        index("title", doc.title, {"store": "yes"});
    }
    if(doc.author){
        index("author", doc.author, {"store": "yes"});
    }
    if(doc.content){
        index("email", doc.email, {"store": "yes"});
    }

}

3) Include couchtable var couchtable = require('couchtable');

4) Use at your own risk. See note above.

EXAMPLE

Example using express.js

var couchtable = require('couchtable');

var table = new couchtable('http://user:pass@localhost');

app.get('/datatable', function(req, res){

  var params = {
    db: 'dbname',
    designname: 'designname',
    viewname: 'couchtable',
    docType: 'users',
    aColumns: ['firstName', 'lastName', 'email'],
    stale: 'ok',
    urlParams: req.params
  };

  table.query(params, function(err, result){
    if(err){
      console.log(err);
    }
    else{
      res.send(result);
    }
  });
});

DOCUMENTATION

query(params, callback)

TODO

  • [ ] Add test cases
  • [ ] Save URL params from being injected with garbage
  • [ ] Add in more detailed and nicer error handling
  • [ ] View generator to create search index automatically
npm loves you