kopia lustrzana https://github.com/simonw/datasette
FTS tables now detected by inspect(), closes #240
rodzic
f188ceaa2a
commit
aa954382c3
|
@ -24,7 +24,7 @@ from .utils import (
|
||||||
Filters,
|
Filters,
|
||||||
CustomJSONEncoder,
|
CustomJSONEncoder,
|
||||||
compound_keys_after_sql,
|
compound_keys_after_sql,
|
||||||
detect_fts_sql,
|
detect_fts,
|
||||||
detect_spatialite,
|
detect_spatialite,
|
||||||
escape_css_string,
|
escape_css_string,
|
||||||
escape_sqlite,
|
escape_sqlite,
|
||||||
|
@ -726,12 +726,7 @@ class TableView(RowTableShared):
|
||||||
where_clauses, params = filters.build_where_clauses()
|
where_clauses, params = filters.build_where_clauses()
|
||||||
|
|
||||||
# _search support:
|
# _search support:
|
||||||
fts_table = None
|
fts_table = info[name]['tables'].get(table, {}).get('fts_table')
|
||||||
fts_sql = detect_fts_sql(table)
|
|
||||||
fts_rows = list(await self.execute(name, fts_sql))
|
|
||||||
if fts_rows:
|
|
||||||
fts_table = fts_rows[0][0]
|
|
||||||
|
|
||||||
search = special_args.get('_search')
|
search = special_args.get('_search')
|
||||||
search_description = None
|
search_description = None
|
||||||
if search and fts_table:
|
if search and fts_table:
|
||||||
|
@ -1252,6 +1247,9 @@ class Datasette:
|
||||||
# This can happen when running against a FTS virtual tables
|
# This can happen when running against a FTS virtual tables
|
||||||
# e.g. "select count(*) from some_fts;"
|
# e.g. "select count(*) from some_fts;"
|
||||||
count = 0
|
count = 0
|
||||||
|
# Does this table have a FTS table?
|
||||||
|
fts_table = detect_fts(conn, table)
|
||||||
|
|
||||||
# Figure out primary keys
|
# Figure out primary keys
|
||||||
table_info_rows = [
|
table_info_rows = [
|
||||||
row for row in conn.execute(
|
row for row in conn.execute(
|
||||||
|
@ -1276,6 +1274,7 @@ class Datasette:
|
||||||
'count': count,
|
'count': count,
|
||||||
'label_column': label_column,
|
'label_column': label_column,
|
||||||
'hidden': table_metadata.get('hidden') or False,
|
'hidden': table_metadata.get('hidden') or False,
|
||||||
|
'fts_table': fts_table,
|
||||||
}
|
}
|
||||||
|
|
||||||
foreign_keys = get_all_foreign_keys(conn)
|
foreign_keys = get_all_foreign_keys(conn)
|
||||||
|
|
|
@ -427,7 +427,7 @@ def detect_spatialite(conn):
|
||||||
return len(rows) > 0
|
return len(rows) > 0
|
||||||
|
|
||||||
|
|
||||||
def detect_fts(conn, table, return_sql=False):
|
def detect_fts(conn, table):
|
||||||
"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()
|
||||||
if len(rows) == 0:
|
if len(rows) == 0:
|
||||||
|
|
|
@ -33,6 +33,7 @@ def test_database_page(app_client):
|
||||||
'hidden': False,
|
'hidden': False,
|
||||||
'foreign_keys': {'incoming': [], 'outgoing': []},
|
'foreign_keys': {'incoming': [], 'outgoing': []},
|
||||||
'label_column': None,
|
'label_column': None,
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': [],
|
'primary_keys': [],
|
||||||
}, {
|
}, {
|
||||||
'columns': ['pk', 'content'],
|
'columns': ['pk', 'content'],
|
||||||
|
@ -41,6 +42,7 @@ def test_database_page(app_client):
|
||||||
'hidden': False,
|
'hidden': False,
|
||||||
'foreign_keys': {'incoming': [], 'outgoing': []},
|
'foreign_keys': {'incoming': [], 'outgoing': []},
|
||||||
'label_column': None,
|
'label_column': None,
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': ['pk'],
|
'primary_keys': ['pk'],
|
||||||
}, {
|
}, {
|
||||||
'columns': ['pk', 'f1', 'f2', 'f3'],
|
'columns': ['pk', 'f1', 'f2', 'f3'],
|
||||||
|
@ -64,6 +66,7 @@ def test_database_page(app_client):
|
||||||
},
|
},
|
||||||
'hidden': False,
|
'hidden': False,
|
||||||
'label_column': None,
|
'label_column': None,
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': ['pk'],
|
'primary_keys': ['pk'],
|
||||||
}, {
|
}, {
|
||||||
'columns': ['pk1', 'pk2', 'content'],
|
'columns': ['pk1', 'pk2', 'content'],
|
||||||
|
@ -72,6 +75,7 @@ def test_database_page(app_client):
|
||||||
'hidden': False,
|
'hidden': False,
|
||||||
'foreign_keys': {'incoming': [], 'outgoing': []},
|
'foreign_keys': {'incoming': [], 'outgoing': []},
|
||||||
'label_column': None,
|
'label_column': None,
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': ['pk1', 'pk2'],
|
'primary_keys': ['pk1', 'pk2'],
|
||||||
}, {
|
}, {
|
||||||
'columns': ['pk1', 'pk2', 'pk3', 'content'],
|
'columns': ['pk1', 'pk2', 'pk3', 'content'],
|
||||||
|
@ -80,6 +84,7 @@ def test_database_page(app_client):
|
||||||
'hidden': False,
|
'hidden': False,
|
||||||
'foreign_keys': {'incoming': [], 'outgoing': []},
|
'foreign_keys': {'incoming': [], 'outgoing': []},
|
||||||
'label_column': None,
|
'label_column': None,
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': ['pk1', 'pk2', 'pk3'],
|
'primary_keys': ['pk1', 'pk2', 'pk3'],
|
||||||
}, {
|
}, {
|
||||||
'columns': ['pk', 'foreign_key_with_custom_label'],
|
'columns': ['pk', 'foreign_key_with_custom_label'],
|
||||||
|
@ -95,6 +100,7 @@ def test_database_page(app_client):
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
'label_column': None,
|
'label_column': None,
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': ['pk'],
|
'primary_keys': ['pk'],
|
||||||
}, {
|
}, {
|
||||||
'columns': ['pk', 'foreign_key_with_label', 'foreign_key_with_no_label'],
|
'columns': ['pk', 'foreign_key_with_label', 'foreign_key_with_no_label'],
|
||||||
|
@ -114,6 +120,7 @@ def test_database_page(app_client):
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
'label_column': None,
|
'label_column': None,
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': ['pk'],
|
'primary_keys': ['pk'],
|
||||||
}, {
|
}, {
|
||||||
'columns': ['id', 'content', 'content2'],
|
'columns': ['id', 'content', 'content2'],
|
||||||
|
@ -129,6 +136,7 @@ def test_database_page(app_client):
|
||||||
},
|
},
|
||||||
'hidden': False,
|
'hidden': False,
|
||||||
'label_column': None,
|
'label_column': None,
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': ['id']
|
'primary_keys': ['id']
|
||||||
}, {
|
}, {
|
||||||
'columns': ['id', 'content', 'content2'],
|
'columns': ['id', 'content', 'content2'],
|
||||||
|
@ -144,6 +152,7 @@ def test_database_page(app_client):
|
||||||
},
|
},
|
||||||
'hidden': False,
|
'hidden': False,
|
||||||
'label_column': None,
|
'label_column': None,
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': ['id']
|
'primary_keys': ['id']
|
||||||
}, {
|
}, {
|
||||||
'columns': ['group', 'having', 'and'],
|
'columns': ['group', 'having', 'and'],
|
||||||
|
@ -152,6 +161,7 @@ def test_database_page(app_client):
|
||||||
'hidden': False,
|
'hidden': False,
|
||||||
'foreign_keys': {'incoming': [], 'outgoing': []},
|
'foreign_keys': {'incoming': [], 'outgoing': []},
|
||||||
'label_column': None,
|
'label_column': None,
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': [],
|
'primary_keys': [],
|
||||||
}, {
|
}, {
|
||||||
'columns': ['id', 'content'],
|
'columns': ['id', 'content'],
|
||||||
|
@ -179,6 +189,7 @@ def test_database_page(app_client):
|
||||||
'outgoing': [],
|
'outgoing': [],
|
||||||
},
|
},
|
||||||
'label_column': 'content',
|
'label_column': 'content',
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': ['id'],
|
'primary_keys': ['id'],
|
||||||
}, {
|
}, {
|
||||||
'columns': [
|
'columns': [
|
||||||
|
@ -190,6 +201,7 @@ def test_database_page(app_client):
|
||||||
'hidden': False,
|
'hidden': False,
|
||||||
'foreign_keys': {'incoming': [], 'outgoing': []},
|
'foreign_keys': {'incoming': [], 'outgoing': []},
|
||||||
'label_column': None,
|
'label_column': None,
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': ['pk1', 'pk2'],
|
'primary_keys': ['pk1', 'pk2'],
|
||||||
}, {
|
}, {
|
||||||
'columns': ['pk', 'content'],
|
'columns': ['pk', 'content'],
|
||||||
|
@ -198,6 +210,7 @@ def test_database_page(app_client):
|
||||||
'hidden': False,
|
'hidden': False,
|
||||||
'foreign_keys': {'incoming': [], 'outgoing': []},
|
'foreign_keys': {'incoming': [], 'outgoing': []},
|
||||||
'label_column': None,
|
'label_column': None,
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': ['pk'],
|
'primary_keys': ['pk'],
|
||||||
}, {
|
}, {
|
||||||
'columns': ['pk', 'distance', 'frequency'],
|
'columns': ['pk', 'distance', 'frequency'],
|
||||||
|
@ -206,6 +219,7 @@ def test_database_page(app_client):
|
||||||
'hidden': False,
|
'hidden': False,
|
||||||
'foreign_keys': {'incoming': [], 'outgoing': []},
|
'foreign_keys': {'incoming': [], 'outgoing': []},
|
||||||
'label_column': None,
|
'label_column': None,
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': ['pk'],
|
'primary_keys': ['pk'],
|
||||||
}, {
|
}, {
|
||||||
'columns': ['content', 'a', 'b', 'c'],
|
'columns': ['content', 'a', 'b', 'c'],
|
||||||
|
@ -214,6 +228,7 @@ def test_database_page(app_client):
|
||||||
'hidden': True,
|
'hidden': True,
|
||||||
'foreign_keys': {'incoming': [], 'outgoing': []},
|
'foreign_keys': {'incoming': [], 'outgoing': []},
|
||||||
'label_column': None,
|
'label_column': None,
|
||||||
|
'fts_table': None,
|
||||||
'primary_keys': [],
|
'primary_keys': [],
|
||||||
}] == data['tables']
|
}] == data['tables']
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue