From: Damian Dimmich Date: Sat, 28 Jun 2014 19:11:03 +0000 (+0400) Subject: minor cleanup of the jsonb - had extraneous operators that where copied X-Git-Tag: rel_1_0_0b1~349^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4eca136e0914252a291046d8c2ed281fe6c56d94;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git minor cleanup of the jsonb - had extraneous operators that where copied from hstore that don't apply. Add tests for ? and @> operators. --- diff --git a/lib/sqlalchemy/dialects/postgresql/json.py b/lib/sqlalchemy/dialects/postgresql/json.py index 262ec20bd3..183cb26954 100644 --- a/lib/sqlalchemy/dialects/postgresql/json.py +++ b/lib/sqlalchemy/dialects/postgresql/json.py @@ -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 diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py index b11c2a46c5..6e6e226236 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -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',)