Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

[Feature Request] make where varargs to specify logic precedence #19

Closed
tsouza opened this Issue · 4 comments

2 participants

Thiago Souza snd
Thiago Souza

Hi,

The following query:

user.select("*").
    where({ username: "user", password: "hash",
        $or: [ { active: 1 }, { active: { $null: true } } ]});

Would produce the following SQL:

 SELECT * FROM user WHERE username = ? AND password = ? AND (active IS NULL) OR (active = ?)

In my case, this is not the intended SQL as "(active IS NULL) OR (active = ?)" needs precedence (i.e. between parentheses), so I suggest that where method to be varags:

user.select("*").
    where({ username: "user", password: "hash"}, 
        { $or: [ { active: 1 }, { active: { $null: true } } ]});

And this would produce the following:

 SELECT * FROM user WHERE (username = ? AND password = ?) AND ((active IS NULL) OR (active = ?))

Att

snd
Owner

your initial query was correct. there should be another pair of parentheses around the $or.
i am going to fix this soon.

Thiago Souza

Hi there,

 Any ETA on fixing this?

Regards

snd
Owner

fixed in version 0.9.2.

i am sorry to have left you waiting so long.

snd snd closed this
Thiago Souza
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.