kopia lustrzana https://github.com/simonw/datasette
rodzic
e47117ce1d
commit
a9b9d42791
|
|
@ -778,14 +778,34 @@ class Datasette:
|
|||
if column_names and len(column_names) == 2 and 'id' in column_names:
|
||||
label_column = [c for c in column_names if c != 'id'][0]
|
||||
tables[table] = {
|
||||
'name': table,
|
||||
'columns': column_names,
|
||||
'count': count,
|
||||
'label_column': label_column,
|
||||
'hidden': False,
|
||||
}
|
||||
|
||||
foreign_keys = get_all_foreign_keys(conn)
|
||||
for table, info in foreign_keys.items():
|
||||
tables[table]['foreign_keys'] = info
|
||||
|
||||
# Mark tables 'hidden' if they relate to FTS virtual tables
|
||||
fts_tables = [
|
||||
r['name']
|
||||
for r in conn.execute(
|
||||
'''
|
||||
select name from sqlite_master
|
||||
where rootpage = 0
|
||||
and sql like '%VIRTUAL TABLE%USING FTS%'
|
||||
'''
|
||||
)
|
||||
]
|
||||
for t in tables.keys():
|
||||
for fts_table in fts_tables:
|
||||
if t == fts_table or t.startswith(fts_table):
|
||||
tables[t]['hidden'] = True
|
||||
continue
|
||||
|
||||
self._inspect[name] = {
|
||||
'hash': m.hexdigest(),
|
||||
'file': str(path),
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ CREATE TABLE "election_results" (
|
|||
FOREIGN KEY (office) REFERENCES office(id)
|
||||
);
|
||||
|
||||
CREATE VIRTUAL TABLE "election_results_fts" USING FTS4 ("county", "party");
|
||||
|
||||
CREATE TABLE "county" (
|
||||
"id" INTEGER PRIMARY KEY ,
|
||||
"name" TEXT
|
||||
|
|
@ -42,7 +44,32 @@ def ds_instance():
|
|||
yield Datasette([filepath])
|
||||
|
||||
|
||||
def test_inspect(ds_instance):
|
||||
def test_inspect_hidden_tables(ds_instance):
|
||||
info = ds_instance.inspect()
|
||||
tables = info['test_tables']['tables']
|
||||
expected_hidden = (
|
||||
'election_results_fts',
|
||||
'election_results_fts_content',
|
||||
'election_results_fts_docsize',
|
||||
'election_results_fts_segdir',
|
||||
'election_results_fts_segments',
|
||||
'election_results_fts_stat',
|
||||
)
|
||||
expected_visible = (
|
||||
'election_results',
|
||||
'county',
|
||||
'party',
|
||||
'office',
|
||||
)
|
||||
assert sorted(expected_hidden) == sorted(
|
||||
[table for table in tables if tables[table]['hidden']]
|
||||
)
|
||||
assert sorted(expected_visible) == sorted(
|
||||
[table for table in tables if not tables[table]['hidden']]
|
||||
)
|
||||
|
||||
|
||||
def test_inspect_foreign_keys(ds_instance):
|
||||
info = ds_instance.inspect()
|
||||
tables = info['test_tables']['tables']
|
||||
for table_name in ('county', 'party', 'office'):
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue