mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
e47117ce1d
commit
a9b9d42791
2 changed files with 48 additions and 1 deletions
|
|
@ -778,14 +778,34 @@ class Datasette:
|
||||||
if column_names and len(column_names) == 2 and 'id' in column_names:
|
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]
|
label_column = [c for c in column_names if c != 'id'][0]
|
||||||
tables[table] = {
|
tables[table] = {
|
||||||
|
'name': table,
|
||||||
|
'columns': column_names,
|
||||||
'count': count,
|
'count': count,
|
||||||
'label_column': label_column,
|
'label_column': label_column,
|
||||||
|
'hidden': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
foreign_keys = get_all_foreign_keys(conn)
|
foreign_keys = get_all_foreign_keys(conn)
|
||||||
for table, info in foreign_keys.items():
|
for table, info in foreign_keys.items():
|
||||||
tables[table]['foreign_keys'] = info
|
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] = {
|
self._inspect[name] = {
|
||||||
'hash': m.hexdigest(),
|
'hash': m.hexdigest(),
|
||||||
'file': str(path),
|
'file': str(path),
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ CREATE TABLE "election_results" (
|
||||||
FOREIGN KEY (office) REFERENCES office(id)
|
FOREIGN KEY (office) REFERENCES office(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE VIRTUAL TABLE "election_results_fts" USING FTS4 ("county", "party");
|
||||||
|
|
||||||
CREATE TABLE "county" (
|
CREATE TABLE "county" (
|
||||||
"id" INTEGER PRIMARY KEY ,
|
"id" INTEGER PRIMARY KEY ,
|
||||||
"name" TEXT
|
"name" TEXT
|
||||||
|
|
@ -42,7 +44,32 @@ def ds_instance():
|
||||||
yield Datasette([filepath])
|
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()
|
info = ds_instance.inspect()
|
||||||
tables = info['test_tables']['tables']
|
tables = info['test_tables']['tables']
|
||||||
for table_name in ('county', 'party', 'office'):
|
for table_name in ('county', 'party', 'office'):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue