tables and views commands accept optional table/view names (#478) - #845
Open
ChrisJr404 wants to merge 1 commit into
Open
tables and views commands accept optional table/view names (#478)#845ChrisJr404 wants to merge 1 commit into
ChrisJr404 wants to merge 1 commit into
Conversation
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 simonw#478
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an optional list of table (or view) names to the
tablesandviewscommands so you can restrict the output to just the tables you care about, rather than always listing everything. This addresses #478.The motivating case from the issue is
--countsagainst a database that contains one very large table: counting every table is expensive, so being able to saysqlite-utils tables data.db small1 small2 --countsand skip the big one is useful.Names are output in the order they are passed. Following the suggestion in the issue that this should error rather than fail silently, an unknown name raises a
ClickExceptionand exits non-zero, so the exit code can be used to confirm that a set of expected tables (or views) exists:The
viewscommand shares thetablescallback, so it picks up the same behaviour against view names.The change is backwards compatible: with no names passed, both commands behave exactly as before.
I added tests covering filtering, argument-order preservation, combining names with
--counts, and the single/multiple missing-name error messages for both commands. The docs (docs/cli.rst) and the cog-generateddocs/cli-reference.rstare updated.black,flake8,mypy,pyrightandcog --checkall pass, and the fulltests/test_cli.pysuite is green.📚 Documentation preview 📚: https://sqlite-utils--845.org.readthedocs.build/en/845/