mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
.get() method plus support for compound primary keys (#40)
* create_table now handles compound primary keys * CLI now accepts multiple --pk for compound primary keys * Docs for compound primary keys with CLI and Python library * New .get() method plus documentation Closes #36, closes #39
This commit is contained in:
parent
65b2156d9c
commit
c65b67ca46
7 changed files with 173 additions and 12 deletions
|
|
@ -302,7 +302,9 @@ def insert_upsert_options(fn):
|
|||
),
|
||||
click.argument("table"),
|
||||
click.argument("json_file", type=click.File(), required=True),
|
||||
click.option("--pk", help="Column to use as the primary key, e.g. id"),
|
||||
click.option(
|
||||
"--pk", help="Columns to use as the primary key, e.g. id", multiple=True
|
||||
),
|
||||
click.option("--nl", is_flag=True, help="Expect newline-delimited JSON"),
|
||||
click.option("-c", "--csv", is_flag=True, help="Expect CSV"),
|
||||
click.option(
|
||||
|
|
@ -348,6 +350,8 @@ def insert_upsert_implementation(
|
|||
if nl and csv:
|
||||
click.echo("Use just one of --nl and --csv", err=True)
|
||||
return
|
||||
if pk and len(pk) == 1:
|
||||
pk = pk[0]
|
||||
if csv:
|
||||
reader = csv_std.reader(json_file)
|
||||
headers = next(reader)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue