Permalink
Browse files

fixed after cradle API changes

fixed after api changes to cradle
  • Loading branch information...
1 parent d361648 commit a8c6d5225bfef652be433174d7fc6ea0d90f3032 Scott Burch committed Mar 10, 2012
Showing with 12 additions and 16 deletions.
  1. +0 −6 README.md
  2. +12 −10 couch-ar.js
View
@@ -1,11 +1,5 @@
# 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
The idea behind couch-ar is to provide an easy to use active record
View
@@ -35,9 +35,11 @@ exports.init = function(config, callback) {
initDomainConstructors();
});
} else {
- db.viewCleanup();
- db.compact();
- initDomainConstructors();
+ db.viewCleanup(function() {
+ db.compact(function() {
+ initDomainConstructors();
+ });
+ });
}
});
@@ -130,8 +132,8 @@ exports.create = function(name, config, constr) {
function addList() {
factory.list = function(callback) {
- var url = ['_design/',name,'/_view/id'].join('');
- db.query('GET', url, function(err, res) {
+ var url = [name,'id'].join('/');
+ db.view(url, function(err, res) {
callback(instantiateResults(res));
})
}
@@ -141,16 +143,16 @@ exports.create = function(name, config, constr) {
function executeView(viewName, value, callback) {
var options = {};
if (Array.isArray(value)) {
- options.startkey = JSON.stringify(value[0]);
- options.endkey = JSON.stringify(value[1]);
+ options.startkey = value[0];
+ options.endkey = value[1];
} else if (typeof(value) == 'object') {
options = value;
} else {
- options.key = JSON.stringify(value);
+ options.key = value;
}
- var url = ['_design/', name, '/_view/', viewName].join('');
- db.query('GET', url, options, function(err, res) {
+ var url = [name, viewName].join('/');
+ db.view(url, options, function(err, res) {
err && console.log(err);
callback(err ? [] : instantiateResults(res));
});

0 comments on commit a8c6d52

Please sign in to comment.