Reputation: 4234
Trying out the query builder knex.js, http://knexjs.org/
exports.deleteProduct = function(inputs, callback) {
//Working
knex( "products" ).select().exec(function(err, resp) { console.log(resp) });
//Not working
knex( "products" ).del().where( "pr_id", 349).exec(function(err, resp) { console.log(resp) });;
}
The select statement works just fine. But not delete, also tried update. The response is 0. The record has not been deleted, have checked the db. I don't get any error if I run console.log(err) either.
Any ideas?
Upvotes: 2
Views: 17235
Reputation: 4234
Solved. I changed the where clause to an object instead.
/*
DELETE /api/project/products/:pr_id HTTP/1.1
*/
exports.deleteProduct = function(inputs, callback) {
var query = knex("products")
.del()
.where({
pr_id:inputs.params.pr_id
});
query.exec( function(err){
if(err) return callback(err);
sendResponse(callback);
})
}
Upvotes: 5