msiemens / tinydb

TinyDB is a lightweight document oriented database optimized for your happiness :)
https://tinydb.readthedocs.org
MIT License
6.84k stars 550 forks source link

Demonstrate the use of `~` as the NOT operator in the README. #563

Closed jkopczyn closed 1 month ago

jkopczyn commented 5 months ago

I had a use case which needed !exists(), and tried NOT/!/not but not ~. Finding that was the name from the docs was not obvious and I'm still not sure where it hides.

I proceeded to then implement a whole duplicate of _generate_test() that had reversed polarity (and this was quite easy and fast, props on being easy to modify), which is probably not the normal result of missing this feature, but it does seem like it's easy to miss. Fortunately, before making a PR for that I considered the other alternative.

At least two other people (asker and answerer) have had this confusion: https://groups.google.com/g/mitappinventortest/c/QKkZL2oWCw8

msiemens commented 1 month ago

I had a use case which needed !exists(), and tried NOT/!/not but not ~. Finding that was the name from the docs was not obvious and I'm still not sure where it hides.

For reference, the operator is mentioned in https://tinydb.readthedocs.io/en/latest/usage.html#query-modifiers:

>>> # Negate a query: >>> db.search(~ (User.name == 'John'))

But I agree that is rather difficult to find. I'll add the names of the boolean operations to the docs in addition to merging your change!