]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add NOT, LSHIFT, RSHIFT
authorjazzthief <mynameisyegor@gmail.com>
Mon, 16 Jan 2023 16:23:56 +0000 (17:23 +0100)
committerjazzthief <mynameisyegor@gmail.com>
Mon, 16 Jan 2023 16:23:56 +0000 (17:23 +0100)
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/operators.py

index 8beca2f3c5a4a0cfd871c8a6e10a7f20c9732153..22aae54c246baae8417159eff8265d951c076481 100644 (file)
@@ -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] = {
index a5c7860e8620ea430e7c72c549c877b21f1423b3..1cc8de1bfa10a2e1b576107e0747c8f35a9dbebe 100644 (file)
@@ -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,