v1a0 / sqllex

The most pythonic ORM (for SQLite and PostgreSQL). Seriously, try it out!
https://v1a0.github.io/sqllex
GNU General Public License v3.0
92 stars 8 forks source link

BUG | SQLite3xSearchCondition / SQLite3xColumn __and__, __or__ #31

Closed v1a0 closed 3 years ago

v1a0 commented 3 years ago

I don't know why but it doesn't works with and, or, but works great with |, &.

urs_id: SQLite3xColumn

(urs_id != 0) & (urs_id != 1) # works great
(urs_id = 0) | (urs_id = 1) # works great
(urs_id != 0) and (urs_id != 1) # returns bullshit -  "urs_id <> 0"
(urs_id = 0) or (urs_id = 1) # returns bullshit - "urs_id = 1"

I'll open an issue about whit bug, but it's not really critical and necessary.

asadafasab commented 3 years ago

__and__ Implements the & operator not and keyword. __or__ means | not or. (if that's what you meant)

v1a0 commented 3 years ago

__and__ Implements the & operator not and keyword. __or__ means | not or. (if that's what you meant)

Not really, I'm taking about: or and | don't work the same, it returns different values for same inputs

upd: yup


print(
    (id_ < 1) or (id_ == 1)
)
# "('t1'.'id'=1)"

print(
    (id_ < 1) | (id_ == 1)
)
# "(('t1'.'id'<1) OR ('t1'.'id'=1))"

P. S. :

type(id_) == SQLite3xColumn

asadafasab commented 3 years ago
[1,2,3] and [3,2,1]
# [3, 2, 1]
[] and [3,2,1]
# []
[] or [3,2,1]
# [3, 2, 1]
"test" or "something"
# 'test'
bool([])
# False
False or True
# True
5 | 2
# 7
5 or 2
# 5

or and | are different type of operators. I think that this article might be helpful.

v1a0 commented 3 years ago

Wow, I didn't know that.

So is there exists some __method__ for class to override how or works for this class?

Like __or__ method override instruction for | operator.

asadafasab commented 3 years ago

Yes but __bool__ have only one argument.