mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Hide Spatialite system tables
They were getting on my nerves.
This commit is contained in:
parent
cca8bf36fe
commit
d08a133140
2 changed files with 18 additions and 3 deletions
|
|
@ -21,6 +21,7 @@ from .utils import (
|
||||||
CustomJSONEncoder,
|
CustomJSONEncoder,
|
||||||
compound_keys_after_sql,
|
compound_keys_after_sql,
|
||||||
detect_fts_sql,
|
detect_fts_sql,
|
||||||
|
detect_spatialite,
|
||||||
escape_css_string,
|
escape_css_string,
|
||||||
escape_sqlite,
|
escape_sqlite,
|
||||||
filters_should_redirect,
|
filters_should_redirect,
|
||||||
|
|
@ -1121,7 +1122,7 @@ class Datasette:
|
||||||
tables[table]['foreign_keys'] = info
|
tables[table]['foreign_keys'] = info
|
||||||
|
|
||||||
# Mark tables 'hidden' if they relate to FTS virtual tables
|
# Mark tables 'hidden' if they relate to FTS virtual tables
|
||||||
fts_tables = [
|
hidden_tables = [
|
||||||
r['name']
|
r['name']
|
||||||
for r in conn.execute(
|
for r in conn.execute(
|
||||||
'''
|
'''
|
||||||
|
|
@ -1131,9 +1132,18 @@ class Datasette:
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if detect_spatialite(conn):
|
||||||
|
# Also hide Spatialite internal tables
|
||||||
|
hidden_tables += [
|
||||||
|
'ElementaryGeometries', 'SpatialIndex', 'geometry_columns',
|
||||||
|
'spatial_ref_sys', 'spatialite_history', 'sql_statements_log',
|
||||||
|
'sqlite_sequence', 'views_geometry_columns', 'virts_geometry_columns'
|
||||||
|
]
|
||||||
|
|
||||||
for t in tables.keys():
|
for t in tables.keys():
|
||||||
for fts_table in fts_tables:
|
for hidden_table in hidden_tables:
|
||||||
if t == fts_table or t.startswith(fts_table):
|
if t == hidden_table or t.startswith(hidden_table):
|
||||||
tables[t]['hidden'] = True
|
tables[t]['hidden'] = True
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -372,6 +372,11 @@ def get_all_foreign_keys(conn):
|
||||||
return table_to_foreign_keys
|
return table_to_foreign_keys
|
||||||
|
|
||||||
|
|
||||||
|
def detect_spatialite(conn):
|
||||||
|
rows = conn.execute('select 1 from sqlite_master where tbl_name = "geometry_columns"').fetchall()
|
||||||
|
return len(rows) > 0
|
||||||
|
|
||||||
|
|
||||||
def detect_fts(conn, table, return_sql=False):
|
def detect_fts(conn, table, return_sql=False):
|
||||||
"Detect if table has a corresponding FTS virtual table and return it"
|
"Detect if table has a corresponding FTS virtual table and return it"
|
||||||
rows = conn.execute(detect_fts_sql(table)).fetchall()
|
rows = conn.execute(detect_fts_sql(table)).fetchall()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue