mirror of
https://github.com/simonw/datasette.git
synced 2026-10-19 07:47:00 +02:00
Merge ac5954bd31 into c435a80030
This commit is contained in:
commit
18a45ca8dd
3 changed files with 44 additions and 2 deletions
|
|
@ -477,6 +477,11 @@ def uninstall(packages, yes):
|
|||
is_flag=True,
|
||||
help="Create database files if they do not exist",
|
||||
)
|
||||
@click.option(
|
||||
"--create-wal",
|
||||
is_flag=True,
|
||||
help="Create database files if they do not exist, in WAL mode",
|
||||
)
|
||||
@click.option(
|
||||
"--crossdb",
|
||||
is_flag=True,
|
||||
|
|
@ -532,6 +537,7 @@ def serve(
|
|||
pdb,
|
||||
open_browser,
|
||||
create,
|
||||
create_wal,
|
||||
crossdb,
|
||||
nolock,
|
||||
ssl_keyfile,
|
||||
|
|
@ -618,12 +624,14 @@ def serve(
|
|||
elif len(directories) == 1:
|
||||
kwargs["config_dir"] = pathlib.Path(directories[0])
|
||||
|
||||
# Verify list of files, create if needed (and --create)
|
||||
# Verify list of files, create if needed (and --create / --create-wal)
|
||||
for file in file_paths:
|
||||
if not pathlib.Path(file).exists():
|
||||
if create:
|
||||
if create or create_wal:
|
||||
conn = sqlite3.connect(file)
|
||||
conn.execute("vacuum")
|
||||
if create_wal:
|
||||
conn.execute("pragma journal_mode=wal")
|
||||
conn.close()
|
||||
else:
|
||||
raise click.ClickException(
|
||||
|
|
|
|||
|
|
@ -132,6 +132,8 @@ Use ``--internal PATH`` or the ``DATASETTE_INTERNAL`` environment variable to pe
|
|||
--pdb Launch debugger on any errors
|
||||
-o, --open Open Datasette in your web browser
|
||||
--create Create database files if they do not exist
|
||||
--create-wal Create database files if they do not exist, in
|
||||
WAL mode
|
||||
--crossdb Enable cross-database joins using the /_memory
|
||||
database
|
||||
--nolock Ignore locking, open locked files in read-only
|
||||
|
|
|
|||
|
|
@ -171,6 +171,7 @@ def test_metadata_yaml():
|
|||
nolock=False,
|
||||
open_browser=False,
|
||||
create=False,
|
||||
create_wal=False,
|
||||
ssl_keyfile=None,
|
||||
ssl_certfile=None,
|
||||
return_instance=True,
|
||||
|
|
@ -462,6 +463,37 @@ def test_serve_create(tmpdir):
|
|||
assert db_path.exists()
|
||||
|
||||
|
||||
def test_serve_create_wal(tmpdir):
|
||||
runner = CliRunner()
|
||||
db_path = tmpdir / "does_not_exist_yet.db"
|
||||
assert not db_path.exists()
|
||||
result = runner.invoke(
|
||||
cli, [str(db_path), "--create-wal", "--get", "/-/databases.json"]
|
||||
)
|
||||
assert result.exit_code == 0, result.output
|
||||
assert db_path.exists()
|
||||
# The new database should be in WAL mode
|
||||
conn = sqlite3.connect(str(db_path))
|
||||
try:
|
||||
assert conn.execute("pragma journal_mode").fetchone()[0] == "wal"
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def test_serve_create_does_not_set_wal(tmpdir):
|
||||
runner = CliRunner()
|
||||
db_path = tmpdir / "does_not_exist_yet.db"
|
||||
result = runner.invoke(
|
||||
cli, [str(db_path), "--create", "--get", "/-/databases.json"]
|
||||
)
|
||||
assert result.exit_code == 0, result.output
|
||||
conn = sqlite3.connect(str(db_path))
|
||||
try:
|
||||
assert conn.execute("pragma journal_mode").fetchone()[0] != "wal"
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("argument", ("-c", "--config"))
|
||||
@pytest.mark.parametrize("format_", ("json", "yaml"))
|
||||
def test_serve_config(tmpdir, argument, format_):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue