CLI now accepts multiple --pk for compound primary keys

This commit is contained in:
Simon Willison 2019-07-14 20:57:57 -07:00
commit f47b5a9e19
2 changed files with 25 additions and 1 deletions

View file

@ -302,7 +302,7 @@ 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="Column 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 +348,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)