sqlite-utils query - to read SQL from stdin, closes #765

This commit is contained in:
Simon Willison 2026-07-07 17:52:26 -07:00
commit 619770bf42
5 changed files with 48 additions and 0 deletions

View file

@ -782,6 +782,25 @@ def test_query_json(db_path, sql, args, expected):
assert expected == result.output.strip()
def test_query_sql_from_stdin(db_path):
# https://github.com/simonw/sqlite-utils/issues/765
db = Database(db_path)
with db.conn:
db["dogs"].insert_all(
[
{"id": 1, "age": 4, "name": "Cleo"},
{"id": 2, "age": 2, "name": "Pancakes"},
]
)
result = CliRunner().invoke(
cli.cli,
["query", db_path, "-"],
input="select name from dogs order by name",
)
assert result.exit_code == 0, result.output
assert json.loads(result.output) == [{"name": "Cleo"}, {"name": "Pancakes"}]
def test_query_json_empty(db_path):
result = CliRunner().invoke(
cli.cli,