Skip to content

Commit

Permalink
.sqlite/.sqlite3 extensions for config directory mode
Browse files Browse the repository at this point in the history
Closes #1646
  • Loading branch information
simonw committed Oct 7, 2022
1 parent eff1124 commit b7fec7f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 4 additions & 1 deletion datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ def __init__(
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()
Expand Down
2 changes: 1 addition & 1 deletion docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions tests/test_config_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"""
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit b7fec7f

Please sign in to comment.