]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
minor cleanup of the jsonb - had extraneous operators that where copied
authorDamian Dimmich <damian@tauri-tec.com>
Sat, 28 Jun 2014 19:11:03 +0000 (23:11 +0400)
committerDamian Dimmich <damian@tauri-tec.com>
Sat, 28 Jun 2014 19:11:03 +0000 (23:11 +0400)
from hstore that don't apply.

Add tests for ? and @> operators.

lib/sqlalchemy/dialects/postgresql/json.py
test/dialect/postgresql/test_types.py

index 262ec20bd3104c1377b63d201767ff73f9b6175f..183cb26954e42047190e23eeb81d73bcf39cebd4 100644 (file)
@@ -280,7 +280,7 @@ class JSONB(JSON):
 
         def _adapt_expression(self, op, other_comparator):
             if isinstance(op, custom_op):
-                if op.opstring in ['?', '?&', '?|', '@>', '<@']:
+                if op.opstring in ['?', '@>']:
                     return op, sqltypes.Boolean
                 if op.opstring == '->':
                     return op, sqltypes.Text
@@ -299,8 +299,4 @@ class JSONB(JSON):
             """
             return self.expr.op('@>')(other)
 
-
-
-
-
 ischema_names['jsonb'] = JSONB
\ No newline at end of file
index b11c2a46c576abe03e387e776a0810fd5900c024..6e6e226236e6f0994504d16f6618a826eff2907e 100644 (file)
@@ -1982,7 +1982,6 @@ class JSONRoundTripTest(fixtures.TablesTest):
                 },
         )
 
-
     def test_unicode_round_trip_python(self):
         engine = self._non_native_engine()
         self._test_unicode_round_trip(engine)
@@ -2001,6 +2000,21 @@ class JSONBTest(JSONTest):
         )
         self.jsoncol = self.test_table.c.test_column
 
+    #Note - add fixture data for arrays []
+
+    def test_where_has_key(self):
+        self._test_where(
+            # hide from 2to3
+            getattr(self.jsoncol, 'has_key')('data'),
+            "test_table.test_column ? %(test_column_1)s"
+        )
+
+    def test_where_contains(self):
+        self._test_where(
+            self.jsoncol.contains('{"k1": "r1v1"}'),
+            "test_table.test_column @> %(test_column_1)s"
+        )
+
 class JSONBRoundTripTest(JSONRoundTripTest):
     __only_on__ = ('postgresql >= 9.4',)