node-querybuilder
node-querybuilder copied to clipboard
Add a parenthesis stack for where
It would be helpful if we could push and pop where statements.
qb.where({foo:'bar'}
qb.pushWhere()
qb.or_where({v1: 1})
qb.or_where({v2: 2})
qb.popWhere()
where foo='bar' and (v1=1 or v2=2)
Query grouping would be a great feature. We would probably syntactically follow the concept in Codeigniter: https://codeigniter.com/user_guide/database/query_builder.html#query-grouping
So, like this:
qb.from('my_table')
.group_start()
.where('a', 'a')
.or_group_start()
.where({b: 'b', c: 'c'})
.group_end()
.group_end()
.where('d', 'd').get(callback);
Which should yield a query like this:
SELECT * FROM (`my_table`) WHERE ( `a` = 'a' OR ( `b` = 'b' AND `c` = 'c' ) ) AND `d` = 'd'
I'm focusing on getting some bugs fixed and adding support for MS SQL at the moment, but, we can add this as an enhancement request for a later release of v2... say, maybe, a v2.1 or something.
Once v2 is out, I'd be open to pull requests from anyone wanting this feature.
I use version 2.1.1 but plugin not support this problem. Pls update new version fix problem