From c1b1df53c8c63e91ee3d751deb7fa3358e6d4075 Mon Sep 17 00:00:00 2001 From: jazzthief Date: Mon, 16 Jan 2023 17:23:56 +0100 Subject: [PATCH] Add NOT, LSHIFT, RSHIFT --- lib/sqlalchemy/sql/compiler.py | 3 +++ lib/sqlalchemy/sql/operators.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 8beca2f3c5..22aae54c24 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -283,6 +283,9 @@ OPERATORS = { operators.bitwise_xor_op: " ^ ", operators.bitwise_or_op: " | ", operators.bitwise_and_op: " & ", + operators.bitwise_not_op: "~", + operators.bitwise_lshift_op: " << ", + operators.bitwise_rshift_op: " >> ", } FUNCTIONS: Dict[Type[Function[Any]], str] = { diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index a5c7860e86..1cc8de1bfa 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -705,6 +705,21 @@ class ColumnOperators(Operators): return self.operate(bitwise_and_op, other) + def bitwise_not(self) -> ColumnOperators: + """Return bitwise NOT operation""" + + return self.operate(bitwise_not_op) + + def bitwise_lshift(self, other: Any) -> ColumnOperators: + """Return bitwise LSHIFT operation""" + + return self.operate(bitwise_lshift_op, other) + + def bitwise_rshift(self, other: Any) -> ColumnOperators: + """Return bitwise RSHIFT operation""" + + return self.operate(bitwise_rshift_op, other) + def in_(self, other: Any) -> ColumnOperators: """Implement the ``in`` operator. @@ -2243,6 +2258,9 @@ _PRECEDENCE: Dict[OperatorType, int] = { bitwise_xor_op: 7, bitwise_or_op: 7, bitwise_and_op: 7, + bitwise_not_op: 7, + bitwise_lshift_op: 7, + bitwise_rshift_op: 7, concat_op: 6, filter_op: 6, match_op: 5, -- 2.47.3