I have an application where I want to list a bunch of Artists by letter. So for example if I enter the letter "L" - the application should return all artists from my DB with the letter "L". I'm pretty new to NodeJS, so maybe someone can help me out?
my routes.js:
server.get('/i/artists/:letter', myartists.getArtistByLetter);
and my artists.js:
exports.getArtistByLetter = function(req, res, next){
var where;
if(req.query == '0-9') // not sure about req.query, probably wrong???
{
where = ["formated_name RLIKE '^[0-9#]' AND artist_parent_id = 0 "];
}
else
{
where = ["formated_name LIKE '"+req.query+"%' AND artist_parent_id = 0"];
}
db.artist.findAll({
where: where,
attributes: ['artist_id', ['formated_name', 'name'], 'uuid', 'slug']
}, {raw: true})
.success(function(artist){
res.json({data: artist});
});
}
After entering http://localhost:2100/i/artists/l
this returns {"data":[]}
...
so, any suggestions? Thanks...