From 24c552a5f4d88eaf4eb30a8a9fb06b0d7ec75bc8 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Mon, 21 May 2018 17:20:42 +0200 Subject: [PATCH] Support for 'distinct' and 'null' queries --- datasette_pytables/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/datasette_pytables/__init__.py b/datasette_pytables/__init__.py index 094710b..a1f11d9 100644 --- a/datasette_pytables/__init__.py +++ b/datasette_pytables/__init__.py @@ -107,8 +107,12 @@ class Connection: operator = list(where)[0] if operator in ['and', 'or']: - subexpr = ["({})".format(_translate_where(q)) for q in where[operator]] + subexpr = [_translate_where(e) for e in where[operator]] + subexpr = filter(lambda e: e, subexpr) + subexpr = ["({})".format(e) for e in subexpr] expr = " {} ".format(_operators[operator]).join(subexpr) + elif operator == 'exists': + pass elif where == {'eq': ['rowid', 'p0']}: nonlocal start, end start = int(params['p0']) @@ -150,16 +154,19 @@ class Connection: for table_row in table_rows: row = Row() for field in fields: - if field['value'] == 'rowid': + field_name = field['value'] + if type(field_name) is dict and 'distinct' in field_name: + field_name = field_name['distinct'] + if field_name == 'rowid': row['rowid'] = int(table_row.nrow) - elif field['value'] == '*': + elif field_name == '*': for col in table.colnames: value = table_row[col] if type(value) is bytes: value = value.decode('utf-8') row[col] = value else: - row[field['value']] = table_row[field['value']] + row[field_name] = table_row[field_name] rows.append(row) # Prepare query description -- 2.39.5