Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Miso Project - Dataset: CouchDB Importer
// Underscore utility
var _ = require("underscore");
// Miso library
var Miso = require("miso.dataset");
// Nano library
var nano = require("nano");
/*
* The Couchdb importer is responsible for fetching data from a CouchDB
* database.
*
* Parameters:
* options
* auth - Authentication to the database server
* host - Address to the database server
* db - Name of the database
* query - Query to make to the database
*/
Miso.Importers.Couchdb = function(options) {
_.defaults(this, options, {
auth: "",
host: "",
db: "",
query: ""
});
// Generate the CouchDB url
var url = [ this.auth, this.host, this.db ].join("");
// Establish a connection
this.connection = nano([ url, this.query && "?" + this.query ].join(""));
};
_.extend(Miso.Importers.Couchdb.prototype, {
fetch: function(options) {
if (_.isFunction(this.view)) {
this.view(this.connection, function(err, data) {
if (err) {
return options.error(err);
}
return options.success(data.rows);
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment