~cjwatson/storm/is-and-is-not-operators

  • Committer: Colin Watson
  • Date: 2022-10-18 17:36:05 UTC
  • Revision ID: cjwatson@canonical.com-20221018173605-1wapeqlnpcd0fju4
Add storm.expr.Is and storm.expr.IsNot operators.

Launchpad has had custom `IsTrue` and `IsFalse` operators for a while,
because there are a few places where `expr` or `expr == True` (or the
equivalents for False) don't quite do what we need: for example, if
you're working with a nullable boolean column, then SQL NULL semantics
mean that `expr = TRUE` or `expr = FALSE` return NULL when `expr` is
NULL, which can be undesirable at times.

In addition, `==` and `!=` comparisons with True/False/None are
typically picked up as errors by modern linters, since in normal Python
code they should use `is` or `is not` or simple boolean tests instead.
Having to override this is an annoyance.

Compare
https://docs.sqlalchemy.org/en/20/core/operators.html#identity-comparisons,
although SQLAlchemy is more permissive; it seems to be happy to compile
anything on the right-hand-side of `IS` or `IS NOT` and leave it up to
the database.  Since we already have to take some care with how booleans
are rendered, and there's no guarantee that the spelling of `IS TRUE`
etc. is going to match the way that boolean values themselves are
spelled, I thought it better to limit the set of right-hand-side
expressions that we will compile.

I've checked that current versions of all the databases currently
supported by Storm (PostgreSQL, MySQL, and SQLite) support all the
resulting expressions, although in the case of SQLite it does need at
least version 3.23.0 (released in 2018).
Filename Latest Rev Last Changed Committer Comment Size
..
dev 424.2.1 12 years ago David Britton Adding some dev setup scripts. Diff
storm 1 18 years ago Gustavo Niemeyer Adding initial infrastructure. Diff
.bzrignore 566.1.3 3 years ago Colin Watson Restore MySQL support. We've had some requests to 339 bytes Diff Download File
doc-requirements.txt 558 3 years ago Colin Watson Add doc-requirements.txt for readthedocs builds. 7 bytes Diff Download File
LICENSE 129 16 years ago Gustavo Niemeyer Added LGPL version 2.1 in the LICENSE file, and a 25.9 KB Diff Download File
Makefile 487.2.1 4 years ago Colin Watson Add tox testing support. 740 bytes Diff Download File
MANIFEST.in 570 3 years ago Colin Watson Fix MANIFEST.in prune syntax. 206 bytes Diff Download File
NEWS 577 1 year ago Colin Watson Add storm.expr.Is and storm.expr.IsNot operators. 28.1 KB Diff Download File
README 566.1.3 3 years ago Colin Watson Restore MySQL support. We've had some requests to 5.6 KB Diff Download File
setup.cfg 413 12 years ago Barry Warsaw Add .tar.gz format. 32 bytes Diff Download File
File setup.py 568.1.1 3 years ago Colin Watson Support Python 3.9. 2.8 KB Diff Download File
TODO 274 15 years ago Gustavo Niemeyer Updated TODO file with Gavin Panella's suggestion 2.4 KB Diff Download File
tox.ini 568.1.1 3 years ago Colin Watson Support Python 3.9. 710 bytes Diff Download File