mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
CREATE INDEX statements on table page, closes #618
This commit is contained in:
parent
deeef8da96
commit
a5defb684f
3 changed files with 46 additions and 1 deletions
|
|
@ -232,7 +232,18 @@ class Database:
|
||||||
)
|
)
|
||||||
if not table_definition_rows:
|
if not table_definition_rows:
|
||||||
return None
|
return None
|
||||||
return table_definition_rows[0][0]
|
bits = [table_definition_rows[0][0] + ";"]
|
||||||
|
# Add on any indexes
|
||||||
|
index_rows = list(
|
||||||
|
await self.ds.execute(
|
||||||
|
self.name,
|
||||||
|
"select sql from sqlite_master where tbl_name = :n and type='index' and sql is not null",
|
||||||
|
{"n": table},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
for index_row in index_rows:
|
||||||
|
bits.append(index_row[0] + ";")
|
||||||
|
return "\n".join(bits)
|
||||||
|
|
||||||
async def get_view_definition(self, view):
|
async def get_view_definition(self, view):
|
||||||
return await self.get_table_definition(view, "view")
|
return await self.get_table_definition(view, "view")
|
||||||
|
|
|
||||||
|
|
@ -514,6 +514,7 @@ CREATE TABLE compound_three_primary_keys (
|
||||||
content text,
|
content text,
|
||||||
PRIMARY KEY (pk1, pk2, pk3)
|
PRIMARY KEY (pk1, pk2, pk3)
|
||||||
);
|
);
|
||||||
|
CREATE INDEX idx_compound_three_primary_keys_content ON compound_three_primary_keys(content);
|
||||||
|
|
||||||
CREATE TABLE foreign_key_references (
|
CREATE TABLE foreign_key_references (
|
||||||
pk varchar(30) primary key,
|
pk varchar(30) primary key,
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,39 @@ def test_row_strange_table_name_with_url_hash(app_client_with_hash):
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"path,expected_definition_sql",
|
||||||
|
[
|
||||||
|
(
|
||||||
|
"/fixtures/facet_cities",
|
||||||
|
"""
|
||||||
|
CREATE TABLE facet_cities (
|
||||||
|
id integer primary key,
|
||||||
|
name text
|
||||||
|
);
|
||||||
|
""".strip(),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"/fixtures/compound_three_primary_keys",
|
||||||
|
"""
|
||||||
|
CREATE TABLE compound_three_primary_keys (
|
||||||
|
pk1 varchar(30),
|
||||||
|
pk2 varchar(30),
|
||||||
|
pk3 varchar(30),
|
||||||
|
content text,
|
||||||
|
PRIMARY KEY (pk1, pk2, pk3)
|
||||||
|
);
|
||||||
|
CREATE INDEX idx_compound_three_primary_keys_content ON compound_three_primary_keys(content);
|
||||||
|
""".strip(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_definition_sql(path, expected_definition_sql, app_client):
|
||||||
|
response = app_client.get(path)
|
||||||
|
pre = Soup(response.body, "html.parser").select_one("pre.wrapped-sql")
|
||||||
|
assert expected_definition_sql == pre.string
|
||||||
|
|
||||||
|
|
||||||
def test_table_cell_truncation():
|
def test_table_cell_truncation():
|
||||||
for client in make_app_client(config={"truncate_cells_html": 5}):
|
for client in make_app_client(config={"truncate_cells_html": 5}):
|
||||||
response = client.get("/fixtures/facetable")
|
response = client.get("/fixtures/facetable")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue