From ceeee81017e5fb0ac03f4a102ffd6cce418f0b05 Mon Sep 17 00:00:00 2001 From: Damian Dimmich Date: Tue, 1 Jul 2014 13:24:30 +0400 Subject: jsonb support for <@, ?| and ?& added. need to see if equality already works. --- lib/sqlalchemy/dialects/postgresql/json.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/dialects/postgresql/json.py') diff --git a/lib/sqlalchemy/dialects/postgresql/json.py b/lib/sqlalchemy/dialects/postgresql/json.py index 183cb2695..d19dbe118 100644 --- a/lib/sqlalchemy/dialects/postgresql/json.py +++ b/lib/sqlalchemy/dialects/postgresql/json.py @@ -279,8 +279,9 @@ class JSONB(JSON): return JSONElement(self.expr, other) def _adapt_expression(self, op, other_comparator): + # How does one do equality?? jsonb also has "=" eg. '[1,2,3]'::jsonb = '[1,2,3]'::jsonb if isinstance(op, custom_op): - if op.opstring in ['?', '@>']: + if op.opstring in ['?', '?&', '?|', '@>', '<@']: return op, sqltypes.Boolean if op.opstring == '->': return op, sqltypes.Text @@ -293,10 +294,26 @@ class JSONB(JSON): """ return self.expr.op('?')(other) + def has_all(self, other): + """Boolean expression. Test for presence of all keys in jsonb + """ + return self.expr.op('?&')(other) + + def has_any(self, other): + """Boolean expression. Test for presence of any key in jsonb + """ + return self.expr.op('?|')(other) + def contains(self, other, **kwargs): """Boolean expression. Test if keys (or array) are a superset of/contained the keys of the argument jsonb expression. """ return self.expr.op('@>')(other) + def contained_by(self, other): + """Boolean expression. Test if keys are a proper subset of the + keys of the argument jsonb expression. + """ + return self.expr.op('<@')(other) + ischema_names['jsonb'] = JSONB \ No newline at end of file -- cgit v1.2.1