mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-08 09:34:08 +02:00
insert-files: support fixed value columns via -c colname:text:value
Extends the -c/--column spec so a column can be populated with a literal value for every inserted file, e.g. -c file_type:text:gif, without a separate update pass. Existing colname:coldef shorthands and compound --pk behavior are unchanged. Closes #140
This commit is contained in:
parent
6a456830ca
commit
71664b8fcf
3 changed files with 74 additions and 2 deletions
|
|
@ -2978,8 +2978,19 @@ def insert_files(
|
|||
"size": lambda p, data=stdin_data: len(data),
|
||||
}
|
||||
for coldef in column:
|
||||
if ":" in coldef:
|
||||
colname, coltype = coldef.rsplit(":", 1)
|
||||
parts = coldef.split(":", 2)
|
||||
if len(parts) == 3:
|
||||
# Fixed value, e.g. -c file_type:text:gif
|
||||
colname, coltype, fixed_value = parts
|
||||
if coltype != "text":
|
||||
raise click.ClickException(
|
||||
"Fixed value column definitions must use "
|
||||
"'colname:text:value', not '{}'".format(coldef)
|
||||
)
|
||||
row[colname] = fixed_value
|
||||
continue
|
||||
elif len(parts) == 2:
|
||||
colname, coltype = parts
|
||||
else:
|
||||
colname, coltype = coldef, coldef
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue