mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-08 09:34:08 +02:00
tables and views commands accept optional table/view names
The tables and views commands now take one or more optional table (or view) names as positional arguments after the database path, restricting the output to just those tables. This is handy with --counts against a database that has a large table you would rather skip. Names are listed in the order they are passed. If any named table or view does not exist the command raises an error and exits with a non-zero status, so the exit code can be used to confirm a set of expected tables is present. Closes #478
This commit is contained in:
parent
56dd09702f
commit
81e2ad8a44
4 changed files with 109 additions and 3 deletions
|
|
@ -140,6 +140,57 @@ def test_tables_schema(db_path):
|
|||
) == result.output.strip()
|
||||
|
||||
|
||||
def test_tables_specific_names(db_path):
|
||||
result = CliRunner().invoke(
|
||||
cli.cli, ["tables", db_path, "Gosh2"], catch_exceptions=False
|
||||
)
|
||||
assert '[{"table": "Gosh2"}]' == result.output.strip()
|
||||
|
||||
|
||||
def test_tables_specific_names_preserve_argument_order(db_path):
|
||||
result = CliRunner().invoke(
|
||||
cli.cli, ["tables", db_path, "Gosh2", "Gosh"], catch_exceptions=False
|
||||
)
|
||||
assert '[{"table": "Gosh2"},\n {"table": "Gosh"}]' == result.output.strip()
|
||||
|
||||
|
||||
def test_tables_specific_names_with_counts(db_path):
|
||||
result = CliRunner().invoke(
|
||||
cli.cli, ["tables", db_path, "Gosh", "--counts"], catch_exceptions=False
|
||||
)
|
||||
assert '[{"table": "Gosh", "count": 0}]' == result.output.strip()
|
||||
|
||||
|
||||
def test_tables_missing_name_errors(db_path):
|
||||
result = CliRunner().invoke(cli.cli, ["tables", db_path, "Gosh", "nope"])
|
||||
assert result.exit_code == 1
|
||||
assert "The following table does not exist: nope" in result.output
|
||||
|
||||
|
||||
def test_tables_multiple_missing_names_errors(db_path):
|
||||
result = CliRunner().invoke(cli.cli, ["tables", db_path, "nope", "nope2"])
|
||||
assert result.exit_code == 1
|
||||
assert "The following tables do not exist: nope, nope2" in result.output
|
||||
|
||||
|
||||
def test_views_specific_names(db_path):
|
||||
db = Database(db_path)
|
||||
db.create_view("v1", "select 1")
|
||||
db.create_view("v2", "select 2")
|
||||
result = CliRunner().invoke(
|
||||
cli.cli, ["views", db_path, "v2"], catch_exceptions=False
|
||||
)
|
||||
assert '[{"view": "v2"}]' == result.output.strip()
|
||||
|
||||
|
||||
def test_views_missing_name_errors(db_path):
|
||||
db = Database(db_path)
|
||||
db.create_view("v1", "select 1")
|
||||
result = CliRunner().invoke(cli.cli, ["views", db_path, "nope"])
|
||||
assert result.exit_code == 1
|
||||
assert "The following view does not exist: nope" in result.output
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"options,expected",
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue