Cleaned up view_definition/table_definition code in table view

Also moved those out of standard JSON into just the HTML template context
This commit is contained in:
Simon Willison 2018-06-16 10:33:17 -07:00
commit 0c22fa8f09
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
2 changed files with 21 additions and 33 deletions

View file

@ -171,6 +171,21 @@ class Datasette:
if query:
return {"name": query_name, "sql": query}
async def get_table_definition(self, database_name, table, type_="table"):
table_definition_rows = list(
await self.execute(
database_name,
'select sql from sqlite_master where name = :n and type=:t',
{"n": table, "t": type_},
)
)
if not table_definition_rows:
return None
return table_definition_rows[0][0]
def get_view_definition(self, database_name, view):
return self.get_table_definition(database_name, view, 'view')
def asset_urls(self, key):
# Flatten list-of-lists from plugins:
seen_urls = set()