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

Nestable queries #15

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

botandrose
Copy link

Hello, thank you for ResoTransport! I'm using this in one of my projects, and its saved me from having to reinvent the wheel.

Working with the query API, I noticed that I wasn't able to construct complex nested queries. My use-case is a client to wanted to pull down all listings within a certain area, but only the active and bumpable-buyer listings. In addition, he wanted to see all of his own listings, regardless of the status. The query looks something like this:

( CountyOrParish = 'Multnomah' or CountyOrParish = 'Clackamas' or CountyOrParish = 'Washington' or CountyOrParish = 'Clark' )
and
(
  ( MlsStatus = 'Active' or MlsStatus = 'BumpableBuyer' )
  or
  ( ListOfficeMlsId eq 'JMAP02'
    and
    ( MlsStatus = 'Pending' or MlsStatus = 'Sold' or MlsStatus = 'SoldNotListed' )
  )
)

This is not possible to construct using the current query API, but it seems to me that there's no reason it couldn't be, like this:

      query.
        eq(CountyOrParish: ["Multnomah", "Clackamas", "Washington", "Clark"]).
        any {
          eq(MlsStatus: ["Active", "BumpableBuyer"])
          all {
            eq(ListOfficeMlsId: "JMAP02")
            eq(MlsStatus: ["Pending", "Sold", "SoldNotListed"])
          }
        }

Note that I have also extended #eq to accept an array for brevity, but that extension is not in this PR. This PR just makes the deep nesting possible.

All existing tests pass with the new implementation, so it should be backwards compatible, but perhaps there are some queries out there that are relying on some idiosyncracy of the old implementation.

Anyways, thoughts? Any interest in merging this?

If desired, I can push a PR for the .eq(field: [1,2,3]) syntax, as well.

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

Successfully merging this pull request may close these issues.

2 participants