.sqlite/.sqlite3 extensions for config directory mode

Closes #1646
pull/1626/merge
Simon Willison 2022-10-07 16:03:09 -07:00
rodzic eff112498e
commit b7fec7f902
3 zmienionych plików z 10 dodań i 8 usunięć

Wyświetl plik

@ -217,7 +217,10 @@ class Datasette:
self._secret = secret or secrets.token_hex(32)
self.files = tuple(files or []) + tuple(immutables or [])
if config_dir:
self.files += tuple([str(p) for p in config_dir.glob("*.db")])
db_files = []
for ext in ("db", "sqlite", "sqlite3"):
db_files.extend(config_dir.glob("*.{}".format(ext)))
self.files += tuple(str(f) for f in db_files)
if (
config_dir
and (config_dir / "inspect-data.json").exists()

Wyświetl plik

@ -46,7 +46,7 @@ Datasette will detect the files in that directory and automatically configure it
The files that can be included in this directory are as follows. All are optional.
* ``*.db`` - SQLite database files that will be served by Datasette
* ``*.db`` (or ``*.sqlite3`` or ``*.sqlite``) - SQLite database files that will be served by Datasette
* ``metadata.json`` - :ref:`metadata` for those databases - ``metadata.yaml`` or ``metadata.yml`` can be used as well
* ``inspect-data.json`` - the result of running ``datasette inspect *.db --inspect-file=inspect-data.json`` from the configuration directory - any database files listed here will be treated as immutable, so they should not be changed while Datasette is running
* ``settings.json`` - settings that would normally be passed using ``--setting`` - here they should be stored as a JSON object of key/value pairs

Wyświetl plik

@ -49,7 +49,7 @@ def config_dir(tmp_path_factory):
(config_dir / "metadata.json").write_text(json.dumps(METADATA), "utf-8")
(config_dir / "settings.json").write_text(json.dumps(SETTINGS), "utf-8")
for dbname in ("demo.db", "immutable.db"):
for dbname in ("demo.db", "immutable.db", "j.sqlite3", "k.sqlite"):
db = sqlite3.connect(str(config_dir / dbname))
db.executescript(
"""
@ -151,12 +151,11 @@ def test_databases(config_dir_client):
response = config_dir_client.get("/-/databases.json")
assert 200 == response.status
databases = response.json
assert 2 == len(databases)
assert 4 == len(databases)
databases.sort(key=lambda d: d["name"])
assert "demo" == databases[0]["name"]
assert databases[0]["is_mutable"]
assert "immutable" == databases[1]["name"]
assert not databases[1]["is_mutable"]
for db, expected_name in zip(databases, ("demo", "immutable", "j", "k")):
assert expected_name == db["name"]
assert db["is_mutable"] == (expected_name != "immutable")
@pytest.mark.parametrize("filename", ("metadata.yml", "metadata.yaml"))