Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Add support for array-ish and clause #68

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

Conversation

anotherpit
Copy link
Contributor

...which also gives you a support for nested and mixed and and or clauses. Like these:

// WHERE color="blue" AND color="red"
Pencil.find({
  where: {
    and: [
      {color: 'blue'},
      {color: 'red'}
    ]
  }
});

// WHERE color="red" AND (color="green" AND color="blue")
Pencil.find({
  where: {
    color: 'red',
    and: [
      {color: 'green'},
      {color: 'blue'}
    ]
  }
});

// WHERE color="red" AND (color="green" AND (color="blue" AND color="yellow"))
Pencil.find({
  where: {
    and: [
      {color: 'red'},
      {
        and: [
          {color: 'green'},
          {
            and: [
              {color: 'blue'},
              {color: 'yellow'}
            ]
          }
        ]
      }
    ]
  }
});

// WHERE (color="red" OR color="green") AND (color="blue" OR color="yellow")
Pencil.find({
  where: {
    and: [
      {
        or: [
          {color: 'red'},
          {color: 'green'}
        ]
      },
      {
        or: [
          {color: 'blue'},
          {color: 'yellow'}
        ]
      }
    ]
  }
});

// WHERE (color="red" AND color="green") OR (color="blue" AND color="yellow")
Pencil.find({
  where: {
    or: [
      {
        and: [
          {color: 'red'},
          {color: 'green'}
        ]
      },
      {
        and: [
          {color: 'blue'},
          {color: 'yellow'}
        ]
      }
    ]
  }
});

Effectively closes https://github.com/balderdashy/waterline/issues/828

@anotherpit
Copy link
Contributor Author

Moreover, according to its tests the fellow waterline-criteria library already supports this syntax for and clause.

@anotherpit
Copy link
Contributor Author

Any thoughts on this PR, guys?

@particlebanana
Copy link
Contributor

@anotherpit I dig it, sorry haven't had time to get into it. We also need some tests in waterline-adapter-tests to show it works in adapters not using wl-sequel such as mongo, etc.

@particlebanana
Copy link
Contributor

@anotherpit also this is supported in the updated criteria/query syntax I'm working on.

@jgeurts
Copy link

jgeurts commented Aug 11, 2016

This would be nice to see get merged. Though, we get around this issue, with the mongo adapter, by using $and for now.

@cyrilchapon
Copy link

Any status on this.. ?

And btw thanks @jgeurts, you made my day with

we get around this issue, with the mongo adapter, by using $and for now.

@AmirTugi
Copy link

AmirTugi commented Jan 4, 2017

@anotherpit Oh my god! This is beautifully done! This is exactly what I was looking for for over 2 months!
It is so banal that I can't believe this wasn't done from the beginning.
When will this be merged already? It is one of the most basic features for a SQL adapter.

@appdevdesigns
Copy link

Yes! We needed this for some of our queries as well. I was about to post a PR with this fix, but @anotherpit did a great job and included tests!

it seems { and:[] } is supported in Sails and waterline-criteria, but just dies here.

I'd love to see this merged soon.

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

Successfully merging this pull request may close these issues.

6 participants