node-querybuilder icon indicating copy to clipboard operation
node-querybuilder copied to clipboard

How to create Nested Or/And clauses?

Open gitcloned opened this issue 7 years ago • 1 comments

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 )

gitcloned avatar Aug 28 '18 17:08 gitcloned

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')

kylefarris avatar Oct 29 '18 14:10 kylefarris