A utility to create clean WHERE statements from an object using the mysql node library
This module will create clean and escaped WHERE statements from an object. It uses a syntax similar to mondob to determine the operators. Simply pass an object to it and will return a string for use in your sql statements.
;// returns "`category` = 'blog' AND `date` <= '2016-01-14' AND `date` >= '2016-01-12' AND `author` != 'steve'"
Here is how you use it with the mysql library.
var createWhere = ;db;
createWhere(statement,join=' AND ')
statement Any normal key / value pairs will be escaped properly and join with a '=' in your where statement. There are also 5 special keys to change there operator.
$gte equates to >=
$lte equates to <=
$gt equates to >
$lt equates to <
$ne equates to !=
join By default these are all joined via ' AND ' but you can pass in a second parameter to act as a different joiner, such as ' OR '
MIT, see LICENSE.md for details.