From a4a38a982aa04f3d08e662c50e55be23cefcc492 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 5 Feb 2010 15:49:02 +0000 Subject: - Added math negation operator support, -x. --- lib/sqlalchemy/sql/compiler.py | 1 + lib/sqlalchemy/sql/expression.py | 6 ++++++ lib/sqlalchemy/sql/operators.py | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index e635e20e1..4486c24db 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -73,6 +73,7 @@ OPERATORS = { # end Py2K operators.mod : ' % ', operators.truediv : ' / ', + operators.neg : '-', operators.lt : ' < ', operators.le : ' <= ', operators.ne : ' != ', diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 5c61777fe..89137d2ce 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -1363,6 +1363,9 @@ class ColumnOperators(Operators): def __ge__(self, other): return self.operate(operators.ge, other) + def __neg__(self): + return self.operate(operators.neg) + def concat(self, other): return self.operate(operators.concat_op, other) @@ -1537,6 +1540,9 @@ class _CompareMixin(ColumnOperators): return self.__compare(op, ClauseList(*args).self_group(against=op), negate=negate_op) + def __neg__(self): + return _UnaryExpression(self, operator=operators.neg) + def startswith(self, other, escape=None): """Produce the clause ``LIKE '%'``""" diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index 879f0f3e5..6f70b1778 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -4,7 +4,7 @@ """Defines operators used in SQL expressions.""" from operator import ( - and_, or_, inv, add, mul, sub, mod, truediv, lt, le, ne, gt, ge, eq + and_, or_, inv, add, mul, sub, mod, truediv, lt, le, ne, gt, ge, eq, neg ) # Py2K @@ -98,6 +98,7 @@ _PRECEDENCE = { div: 7, # end Py2K mod: 7, + neg: 7, add: 6, sub: 6, concat_op: 6, -- cgit v1.2.1