]> git.jsancho.org Git - datasette-pytables.git/blobdiff - datasette_pytables/__init__.py
custom pytables sql
[datasette-pytables.git] / datasette_pytables / __init__.py
index a730cb7e72daae411a7c4c791e759fdd1a4d29a1..9dc2a099bc32666af22122d94f19d39d4da532a5 100644 (file)
@@ -22,6 +22,8 @@ class PyTablesConnector(dc.Connector):
         'lte': '<=',
         'and': '&',
         'or': '|',
+        'binary_and': '&',
+        'binary_or': '|',
     }
 
     def table_names(self):
@@ -127,12 +129,22 @@ class PyTablesConnector(dc.Connector):
                 start = int(params['p0']) + 1
             else:
                 left, right = where[operator]
-                if left in params:
+
+                if isinstance(left, dict):
+                    left = "(" + _translate_where(left) + ")"
+                elif left in params:
                     _cast_param(right, left)
+
+                if isinstance(right, dict):
+                    right = "(" + _translate_where(right) + ")"
                 elif right in params:
                     _cast_param(left, right)
 
-                expr = "{left} {operator} {right}".format(left=left, operator=self.operators.get(operator, operator), right=right)
+                expr = "{left} {operator} {right}".format(
+                    left=left,
+                    operator=self.operators.get(operator, operator),
+                    right=right,
+                )
 
             return expr