Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a parenthesis stack for where #29

Open
Flamenco opened this issue Jun 24, 2018 · 2 comments
Open

Add a parenthesis stack for where #29

Flamenco opened this issue Jun 24, 2018 · 2 comments
Milestone

Comments

@Flamenco
Copy link

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)
@kylefarris
Copy link
Owner

kylefarris commented Jun 25, 2018

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.

@anphamhoai133
Copy link

I use version 2.1.1 but plugin not support this problem. Pls update new version fix problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants