Skip to content

Instantly share code, notes, and snippets.

@boxxxie
Created November 5, 2011 22:51
Show Gist options
  • Save boxxxie/1342134 to your computer and use it in GitHub Desktop.
Save boxxxie/1342134 to your computer and use it in GitHub Desktop.
var couchCollection = function(couch,options){
couch || (couch = {});
couch.db || (couch.db = 'db');
options || (options = {});
var urlBase = window.location.protocol + "//" + window.location.hostname + ":" +window.location.port + "/";
return Backbone.Collection.extend(
_.extend(options,
{url:urlBase + couch.db,
parse: function(response) {
return _(response.rows)
.reject(function(item){return item.id.search('_design') == 0;}) //reject design docs
.pluck('doc')
.value();
},
fetch:function(options){
Backbone
.Collection
.prototype
.fetch
.call(this,_.extend(options,{url:this.url+"/_all_docs",
data:{include_docs:true}}
));
}
}));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment