Test and docs for using :memory: as a filename

This commit is contained in:
Simon Willison 2019-10-04 09:17:27 -07:00
commit eb39c84a8f
2 changed files with 19 additions and 0 deletions

View file

@ -55,6 +55,11 @@ If you want to pretty-print the output further, you can pipe it through ``python
}
]
You can run queries against a temporary in-memory database by passing ``:memory:`` as the filename::
$ sqlite-utils :memory: "select sqlite_version()"
[{"sqlite_version()": "3.29.0"}]
.. _cli_json_values:
Nested JSON values

View file

@ -724,6 +724,20 @@ def test_query_json_with_json_cols(db_path):
assert expected == result_rows.output.strip()
def test_query_memory_does_not_create_file(tmpdir):
owd = os.getcwd()
try:
os.chdir(tmpdir)
# This should create a foo.db file
CliRunner().invoke(cli.cli, ["foo.db", "select sqlite_version()"])
# This should NOT create a file
result = CliRunner().invoke(cli.cli, [":memory:", "select sqlite_version()"])
assert ["sqlite_version()"] == list(json.loads(result.output)[0].keys())
finally:
os.chdir(owd)
assert ["foo.db"] == os.listdir(tmpdir)
@pytest.mark.parametrize(
"args,expected",
[