summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/json.py
diff options
context:
space:
mode:
authorDamian Dimmich <damian@tauri-tec.com>2014-07-01 13:24:30 +0400
committerDamian Dimmich <damian@tauri-tec.com>2014-07-01 13:24:30 +0400
commitceeee81017e5fb0ac03f4a102ffd6cce418f0b05 (patch)
treeb78060b91fa8f1d1bdbe86f911874104f7e4f0bf /lib/sqlalchemy/dialects/postgresql/json.py
parent7f402761d91a79afd01072d7ab6e83bf64106ddc (diff)
downloadsqlalchemy-pr/101.tar.gz
jsonb support for <@, ?| and ?& added.pr/101
need to see if equality already works.
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/json.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/json.py19
1 files changed, 18 insertions, 1 deletions
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