mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-10 02:24:22 +02:00
sqlite-utils rows -c, closes #200
This commit is contained in:
parent
309ae84336
commit
6863dc2677
3 changed files with 16 additions and 1 deletions
|
|
@ -198,6 +198,12 @@ You can return every row in a specified table using the ``rows`` command::
|
||||||
|
|
||||||
This command accepts the same output options as ``query`` - so you can pass ``--nl``, ``--csv``, ``--tsv``, ``--no-headers``, ``--table`` and ``--fmt``.
|
This command accepts the same output options as ``query`` - so you can pass ``--nl``, ``--csv``, ``--tsv``, ``--no-headers``, ``--table`` and ``--fmt``.
|
||||||
|
|
||||||
|
You can use the ``-c`` option to specify a subset of columns to return::
|
||||||
|
|
||||||
|
$ sqlite-utils rows dogs.db dogs -c age -c name
|
||||||
|
[{"age": 4, "name": "Cleo"},
|
||||||
|
{"age": 2, "name": "Pancakes"}]
|
||||||
|
|
||||||
.. _cli_tables:
|
.. _cli_tables:
|
||||||
|
|
||||||
Listing tables
|
Listing tables
|
||||||
|
|
|
||||||
|
|
@ -1061,6 +1061,7 @@ def search(
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
@click.argument("dbtable")
|
@click.argument("dbtable")
|
||||||
|
@click.option("-c", "--column", type=str, multiple=True, help="Columns to return")
|
||||||
@output_options
|
@output_options
|
||||||
@load_extension_option
|
@load_extension_option
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
|
|
@ -1068,6 +1069,7 @@ def rows(
|
||||||
ctx,
|
ctx,
|
||||||
path,
|
path,
|
||||||
dbtable,
|
dbtable,
|
||||||
|
column,
|
||||||
nl,
|
nl,
|
||||||
arrays,
|
arrays,
|
||||||
csv,
|
csv,
|
||||||
|
|
@ -1079,10 +1081,13 @@ def rows(
|
||||||
load_extension,
|
load_extension,
|
||||||
):
|
):
|
||||||
"Output all rows in the specified table"
|
"Output all rows in the specified table"
|
||||||
|
columns = "*"
|
||||||
|
if column:
|
||||||
|
columns = ", ".join("[{}]".format(c) for c in column)
|
||||||
ctx.invoke(
|
ctx.invoke(
|
||||||
query,
|
query,
|
||||||
path=path,
|
path=path,
|
||||||
sql="select * from [{}]".format(dbtable),
|
sql="select {} from [{}]".format(columns, dbtable),
|
||||||
nl=nl,
|
nl=nl,
|
||||||
arrays=arrays,
|
arrays=arrays,
|
||||||
csv=csv,
|
csv=csv,
|
||||||
|
|
|
||||||
|
|
@ -1039,6 +1039,10 @@ def test_query_memory_does_not_create_file(tmpdir):
|
||||||
),
|
),
|
||||||
(["--arrays"], '[[1, "Cleo", 4],\n [2, "Pancakes", 2]]'),
|
(["--arrays"], '[[1, "Cleo", 4],\n [2, "Pancakes", 2]]'),
|
||||||
(["--arrays", "--nl"], '[1, "Cleo", 4]\n[2, "Pancakes", 2]'),
|
(["--arrays", "--nl"], '[1, "Cleo", 4]\n[2, "Pancakes", 2]'),
|
||||||
|
(
|
||||||
|
["--nl", "-c", "age", "-c", "name"],
|
||||||
|
'{"age": 4, "name": "Cleo"}\n{"age": 2, "name": "Pancakes"}',
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_rows(db_path, args, expected):
|
def test_rows(db_path, args, expected):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue