kylefarris / node-querybuilder

Node QueryBuilder Adapter for Node.js (tags: nodejs, node, mysql, active record, activerecord, querybuilder, query builder)
49 stars 19 forks source link

How to create Nested Or/And clauses? #43

Open gitcloned opened 6 years ago

gitcloned commented 6 years ago

How to generate the query clause with nested and/or, example:

Select departmentName, departmentSales
From Department
Where
  EmployeeCount > 1000
  AND (  DepartmentRevenue > 100000 OR DepartmentCost > 10000 )
kylefarris commented 5 years ago

At the moment, you have to escape a manually-written where clause and tell the where method to not try and escape it for you by passing false to the third parameter. There's already an Issue in for the request to add this to the actual API (#29). To do it manually, you would do the following:

qb.select('departmentName', 'departmentSales')
    .where('EmployeeCount >', 1000)
    .where('`DepartmentRevenue` > 100000 OR `DepartmentCost` > 10000', null, false)
   .get('Department')