Skip to content

Commit

Permalink
fixed after cradle API changes
Browse files Browse the repository at this point in the history
fixed after api changes to cradle
  • Loading branch information
Scott Burch committed Mar 10, 2012
1 parent d361648 commit a8c6d52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
6 changes: 0 additions & 6 deletions README.md
@@ -1,11 +1,5 @@
# couch-ar is a thin active record implementation for couchDB # couch-ar is a thin active record implementation for couchDB


## Important Notes
Previous versions of couch-ar included a bug that would cause the domain constructor finder methods not to work if you restarted the server.
This appears to be due to a bug in newer versions of CouchDB. I am not sure when it appeared, but I have modified the code to deal with it.

couch-ar appears to be broken with the newer version of cradle. Since couch-ar relys on cradle, and they changed their API, please use an older version until this can be resolved.

## Motivation ## Motivation


The idea behind couch-ar is to provide an easy to use active record The idea behind couch-ar is to provide an easy to use active record
Expand Down
22 changes: 12 additions & 10 deletions couch-ar.js
Expand Up @@ -35,9 +35,11 @@ exports.init = function(config, callback) {
initDomainConstructors(); initDomainConstructors();
}); });
} else { } else {
db.viewCleanup(); db.viewCleanup(function() {
db.compact(); db.compact(function() {
initDomainConstructors(); initDomainConstructors();
});
});
} }
}); });


Expand Down Expand Up @@ -130,8 +132,8 @@ exports.create = function(name, config, constr) {


function addList() { function addList() {
factory.list = function(callback) { factory.list = function(callback) {
var url = ['_design/',name,'/_view/id'].join(''); var url = [name,'id'].join('/');
db.query('GET', url, function(err, res) { db.view(url, function(err, res) {
callback(instantiateResults(res)); callback(instantiateResults(res));
}) })
} }
Expand All @@ -141,16 +143,16 @@ exports.create = function(name, config, constr) {
function executeView(viewName, value, callback) { function executeView(viewName, value, callback) {
var options = {}; var options = {};
if (Array.isArray(value)) { if (Array.isArray(value)) {
options.startkey = JSON.stringify(value[0]); options.startkey = value[0];
options.endkey = JSON.stringify(value[1]); options.endkey = value[1];
} else if (typeof(value) == 'object') { } else if (typeof(value) == 'object') {
options = value; options = value;
} else { } else {
options.key = JSON.stringify(value); options.key = value;
} }


var url = ['_design/', name, '/_view/', viewName].join(''); var url = [name, viewName].join('/');
db.query('GET', url, options, function(err, res) { db.view(url, options, function(err, res) {
err && console.log(err); err && console.log(err);
callback(err ? [] : instantiateResults(res)); callback(err ? [] : instantiateResults(res));
}); });
Expand Down

0 comments on commit a8c6d52

Please sign in to comment.