I want to consider the where clause only if 'req.query.p' is defined:
exports.select = function(req, res) {
db.Pelicula
.findAndCountAll({
limit : req.query.limit,
offset : req.query.offset,
where : ["nombre = ?", req.query.p]
})
.success(function(resp){
console.log(JSON.stringify(resp.rows, null, 4).bold.get);
res.json({peliculas : resp.rows, meta : { total : resp.count}});
});
}
You can do:
where : req.query.p ? ["nombre = ?", req.query.p] : null