json-and-or-prepared
Use a JSON object to represent a logical conditional statement and convert that to a SQL ready prepared statement string along with an array of corresponding values.
example
var andor =var cond = field:"value"or:one:1two:2fun:"yes"console
output:
Object {condition: "(field = ? AND (one = ? OR two = ?) AND fun = ?)", params: ["value",1,2,"yes"]}
JSON object parameters are by default "and-ed" conditions. To introduce an "or-ed" condition insert a parameter named "or" and provide an array containing objects that represent the field/value combinations to be "or-ed".
example
var andor =var cond = field:"one""two""three"console
output:
Object {condition: "(field IN (?,?,?))", params: ["one","two","three"]}
Use an array of values in place of a parameter value to provide a list of field options.
example
var andor =var cond = field:"value"or:one:1two:2three:"three"console
output:
Object {condition: "(field = ? AND (one = ? OR (two = ? AND three = ?)))", params: ["value",1,2,"three"]}
Generally speaking, "and-ed" expressions are listed in objects, and "or-ed" expressions are listed in arrays.
install
npm install json-and-or-prepared
license
MIT