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
15
docs/cli.rst
15
docs/cli.rst
|
|
@ -747,6 +747,19 @@ You can list the names of tables in a database using the ``tables`` command:
|
|||
{"table": "cats"},
|
||||
{"table": "chickens"}]
|
||||
|
||||
Pass one or more table names to restrict the output to just those tables. This is useful with ``--counts`` against a database that has a large table you want to skip:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
sqlite-utils tables mydb.db dogs cats --counts
|
||||
|
||||
.. code-block:: output
|
||||
|
||||
[{"table": "dogs", "count": 12},
|
||||
{"table": "cats", "count": 332}]
|
||||
|
||||
The tables are listed in the order you name them. An error is raised, and a non-zero exit code returned, if any of the named tables do not exist.
|
||||
|
||||
You can output this list in CSV using the ``--csv`` or ``--tsv`` options:
|
||||
|
||||
.. code-block:: bash
|
||||
|
|
@ -843,6 +856,8 @@ It takes the same options as the ``tables`` command:
|
|||
* ``--tsv``
|
||||
* ``--table``
|
||||
|
||||
As with ``tables``, you can pass one or more view names to restrict the output to just those views.
|
||||
|
||||
.. note::
|
||||
In Python: :ref:`db.views or db.view_names() <python_api_views>` CLI reference: :ref:`sqlite-utils views <cli_ref_views>`
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue