mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Removed .inspect() and /-/inspect.json
Refs #462 /-/inspect.json may return in some shape in #465
This commit is contained in:
parent
1937026766
commit
909e66dfdb
2 changed files with 1 additions and 45 deletions
|
|
@ -538,39 +538,6 @@ class Datasette:
|
||||||
url = "https://" + url[len("http://") :]
|
url = "https://" + url[len("http://") :]
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def inspect(self):
|
|
||||||
" Inspect the database and return a dictionary of table metadata "
|
|
||||||
if self._inspect:
|
|
||||||
return self._inspect
|
|
||||||
|
|
||||||
self._inspect = {}
|
|
||||||
for filename in self.files:
|
|
||||||
if filename is MEMORY:
|
|
||||||
self._inspect[":memory:"] = {
|
|
||||||
"hash": "000",
|
|
||||||
"file": ":memory:",
|
|
||||||
"size": 0,
|
|
||||||
"views": {},
|
|
||||||
"tables": {},
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
path = Path(filename)
|
|
||||||
name = path.stem
|
|
||||||
if name in self._inspect:
|
|
||||||
raise Exception("Multiple files with same stem %s" % name)
|
|
||||||
with sqlite3.connect("file:{}?mode=ro".format(path), uri=True) as conn:
|
|
||||||
self.prepare_connection(conn)
|
|
||||||
self._inspect[name] = {
|
|
||||||
"hash": inspect_hash(path),
|
|
||||||
"file": str(path),
|
|
||||||
"size": path.stat().st_size,
|
|
||||||
"views": inspect_views(conn),
|
|
||||||
"tables": inspect_tables(
|
|
||||||
conn, (self.metadata("databases") or {}).get(name, {})
|
|
||||||
),
|
|
||||||
}
|
|
||||||
return self._inspect
|
|
||||||
|
|
||||||
def register_custom_units(self):
|
def register_custom_units(self):
|
||||||
"Register any custom units defined in the metadata.json with Pint"
|
"Register any custom units defined in the metadata.json with Pint"
|
||||||
for unit in self.metadata("custom_units") or []:
|
for unit in self.metadata("custom_units") or []:
|
||||||
|
|
@ -821,10 +788,6 @@ class Datasette:
|
||||||
if plugin["static_path"]:
|
if plugin["static_path"]:
|
||||||
modpath = "/-/static-plugins/{}/".format(plugin["name"])
|
modpath = "/-/static-plugins/{}/".format(plugin["name"])
|
||||||
app.static(modpath, plugin["static_path"])
|
app.static(modpath, plugin["static_path"])
|
||||||
app.add_route(
|
|
||||||
JsonDataView.as_view(self, "inspect.json", self.inspect),
|
|
||||||
r"/-/inspect<as_format:(\.json)?$>",
|
|
||||||
)
|
|
||||||
app.add_route(
|
app.add_route(
|
||||||
JsonDataView.as_view(self, "metadata.json", lambda: self._metadata),
|
JsonDataView.as_view(self, "metadata.json", lambda: self._metadata),
|
||||||
r"/-/metadata<as_format:(\.json)?$>",
|
r"/-/metadata<as_format:(\.json)?$>",
|
||||||
|
|
|
||||||
|
|
@ -1063,11 +1063,6 @@ def test_metadata_json(app_client):
|
||||||
assert METADATA == response.json
|
assert METADATA == response.json
|
||||||
|
|
||||||
|
|
||||||
def test_inspect_json(app_client):
|
|
||||||
response = app_client.get("/-/inspect.json")
|
|
||||||
assert app_client.ds.inspect() == response.json
|
|
||||||
|
|
||||||
|
|
||||||
def test_plugins_json(app_client):
|
def test_plugins_json(app_client):
|
||||||
response = app_client.get("/-/plugins.json")
|
response = app_client.get("/-/plugins.json")
|
||||||
assert [
|
assert [
|
||||||
|
|
@ -1411,9 +1406,7 @@ def test_ttl_parameter(app_client, path, expected_cache_control):
|
||||||
)
|
)
|
||||||
def test_hash_parameter(app_client_with_hash, path, expected_redirect):
|
def test_hash_parameter(app_client_with_hash, path, expected_redirect):
|
||||||
# First get the current hash for the fixtures database
|
# First get the current hash for the fixtures database
|
||||||
current_hash = app_client_with_hash.get("/-/inspect.json").json["fixtures"]["hash"][
|
current_hash = app_client_with_hash.ds.databases["fixtures"].hash[:7]
|
||||||
:7
|
|
||||||
]
|
|
||||||
response = app_client_with_hash.get(path, allow_redirects=False)
|
response = app_client_with_hash.get(path, allow_redirects=False)
|
||||||
assert response.status == 302
|
assert response.status == 302
|
||||||
location = response.headers["Location"]
|
location = response.headers["Location"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue