Skip to content

Add a parenthesis stack for where #29

Description

@Flamenco

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)

Activity

  1. kylefarris commented on Jun 25, 2018

    @kylefarris
    Owner

    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.

  2. added this to the v2.1 milestone on Jun 25, 2018
  3. anphamhoai133 commented on Mar 28, 2022

    @anphamhoai133

    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions