node-querybuilder
node-querybuilder copied to clipboard
How to create Nested Or/And clauses?
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 )
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')