I am trying to save a javascript object with cradle in NodeJS but I do not get a response or an error message after the save. Its a local couchdb with no password set. The connection is ok and the database exists. I am also using iriscouch follow https://github.com/iriscouch/follow . So when a change is made in the wages table the save employee method is called. The follow works, as I have debugged it but no save is taking place.
Here is my code.
var employeedb = new(cradle.Connection)().database('employees');
employeedb.exists(function (err, exists) {
if (err) {
console.log('error', err);
} else if (exists) {
console.log('Database exists');
} else {
console.log('database does not exists.');
db.create();
/* populate design documents */
}
});
follow({db:"http://localhost:5984/wages", include_docs:true}, function(error, change) {
if(!error) {
var employee ={};
employee.name = 'Tom';
saveEmployee(employee);
}
})
// simple callback after cradle save
function saveHandler(er, doc){
if (er) return console.log('Error: ', er);
console.log(doc);
}
function saveEmployee(employee){
//need to check if result exists for that runner and event
var returnData = {};
employeedb.save(employee, saveHandler);
}
The code works fine for me, I needed to add
to the top of your code, and change
for it to 'compile', but after that it adds Tom to the database.