]> git.jsancho.org Git - datasette-pytables.git/commitdiff
Only tables have columns with types
authorJavier Sancho <jsf@jsancho.org>
Fri, 30 Oct 2020 19:09:05 +0000 (20:09 +0100)
committerJavier Sancho <jsf@jsancho.org>
Fri, 30 Oct 2020 19:09:05 +0000 (20:09 +0100)
datasette_pytables/__init__.py

index c4087730d24699c52968cb34b1de0955635b24a0..9cb90051037c91770f7b10af62dc7ea21435e5e1 100644 (file)
@@ -118,12 +118,16 @@ class PyTablesConnector(dc.Connector):
         start = 0
         end = table.nrows
 
-        # Use 'where' statement or get all the rows
-        def _cast_param(field, pname):
-            # Cast value to the column type
+        def _get_field_type(field):
             coltype = table.dtype.name
             if type(table) is tables.table.Table:
                 coltype = table.coltypes[field]
+            return coltype
+
+        # Use 'where' statement or get all the rows
+        def _cast_param(field, pname):
+            # Cast value to the column type
+            coltype = _get_field_type(field)
             fcast = None
             if coltype == 'string':
                 fcast = str
@@ -266,7 +270,7 @@ class PyTablesConnector(dc.Connector):
                         row['count(*)'] = int(table.nrows)
                     elif field_name.get('json_type'):
                         field_name = field_name.get('json_type')
-                        row['json_type(' + field_name + ')'] = table.coltypes[field_name]
+                        row['json_type(' + field_name + ')'] = _get_field_type(field)
                     else:
                         raise Exception("Function not recognized")
                 else: