New introspection endpoint: /-/databases - closes #470

Refs #419 and #465
This commit is contained in:
Simon Willison 2019-05-16 07:49:34 -07:00
commit 0dad111d24
4 changed files with 57 additions and 0 deletions

View file

@ -549,6 +549,19 @@ class Datasette:
for unit in self.metadata("custom_units") or []:
ureg.define(unit)
def connected_databases(self):
return [
{
"name": d.name,
"path": d.path,
"size": d.size,
"is_mutable": d.is_mutable,
"is_memory": d.is_memory,
"hash": d.hash,
}
for d in self.databases.values()
]
def versions(self):
conn = sqlite3.connect(":memory:")
self.prepare_connection(conn)
@ -810,6 +823,10 @@ class Datasette:
JsonDataView.as_view(self, "config.json", lambda: self._config),
r"/-/config<as_format:(\.json)?$>",
)
app.add_route(
JsonDataView.as_view(self, "databases.json", self.connected_databases),
r"/-/databases<as_format:(\.json)?$>",
)
app.add_route(
DatabaseDownload.as_view(self), r"/<db_name:[^/]+?><as_db:(\.db)$>"
)