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:
Parker Gurney 2026-08-05 14:06:58 -07:00
commit 71664b8fcf
3 changed files with 74 additions and 2 deletions

View file

@ -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: