couchtable
v0.0.1-6
Published
Node.js server module for querying couchdb and returning results to jQuery datatables.
Downloads
3
Readme
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
- Node.js
- CouchDB
- couchdb-lucene (https://github.com/rnewson/couchdb-lucene)
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"});
}
}
Include couchtable
var couchtable = require('couchtable');
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