dc6823472e8abdf6190009648a83d8a6f79122f6
[datasette-pytables.git] / datasette_pytables / __init__.py
1 import tables
2
3 _connector_type = 'pytables'
4
5 def inspect(path):
6     "Open file and return tables info"
7     h5tables = {}
8     views = []
9     h5file = tables.open_file(path)
10
11     for table in filter(lambda node: not(isinstance(node, tables.group.Group)), h5file):
12         colnames = []
13         if isinstance(table, tables.table.Table):
14             colnames = table.colnames
15
16         h5tables[table._v_pathname] = {
17             'name': table._v_pathname,
18             'columns': colnames,
19             'primary_keys': [],
20             'count': table.nrows,
21             'label_column': None,
22             'hidden': False,
23             'fts_table': None,
24             'foreign_keys': {'incoming': [], 'outgoing': []},
25         }
26
27     h5file.close()
28     return h5tables, views, _connector_type
29
30 class Connection:
31     def __init__(self, path):
32         self.path = path
33         self.h5file = tables.open_file(path)
34
35     def execute(self, sql, params):
36         return [], False, []