Search code examples
node.jssqliteparameterization

mapbox's node sqlite3 - using LIKE with parameterization correctly


So I spent more time than I'd like to disclose finding out this little bit of undocumented gem:

So when you're doing something like: db.all(sql,params,callback)

this wont work

where params and sql is something like:

var params = { $param1 : 'some string' };
var sql = 'select * from FOO where FOO.name LIKE "%$param1%"';

Answered below.


Solution

  • this works

    var params = { $param1 : '%' + 'some string' + '%' };
    var sql = 'select * from FOO where FOO.name LIKE $param1';
    

    I hope this helps someone out there - because no amount of googling would have got me to this answer.