]> git.jsancho.org Git - datasette-pytables.git/blobdiff - datasette_pytables/__init__.py
PyTables Connection class
[datasette-pytables.git] / datasette_pytables / __init__.py
index 8593aedf957f65bed58318c639aa10fb26a4f572..dc6823472e8abdf6190009648a83d8a6f79122f6 100644 (file)
@@ -1,6 +1,36 @@
-from datasette.connectors import connector_method
+import tables
+
+_connector_type = 'pytables'
 
-@connector_method
 def inspect(path):
     "Open file and return tables info"
-    return [], []
+    h5tables = {}
+    views = []
+    h5file = tables.open_file(path)
+
+    for table in filter(lambda node: not(isinstance(node, tables.group.Group)), h5file):
+        colnames = []
+        if isinstance(table, tables.table.Table):
+            colnames = table.colnames
+
+        h5tables[table._v_pathname] = {
+            'name': table._v_pathname,
+            'columns': colnames,
+            'primary_keys': [],
+            'count': table.nrows,
+            'label_column': None,
+            'hidden': False,
+            'fts_table': None,
+            'foreign_keys': {'incoming': [], 'outgoing': []},
+        }
+
+    h5file.close()
+    return h5tables, views, _connector_type
+
+class Connection:
+    def __init__(self, path):
+        self.path = path
+        self.h5file = tables.open_file(path)
+
+    def execute(self, sql, params):
+        return [], False, []