mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
--convert --text for iterators, docs for --convert
This commit is contained in:
parent
2e4847e493
commit
413f8ed754
3 changed files with 136 additions and 13 deletions
|
|
@ -814,7 +814,16 @@ def insert_upsert_implementation(
|
|||
if lines:
|
||||
docs = (fn(doc["line"]) for doc in docs)
|
||||
elif text:
|
||||
docs = (fn(doc["text"]) for doc in docs)
|
||||
# Special case: this is allowed to be an iterable
|
||||
text_value = list(docs)[0]["text"]
|
||||
fn_return = fn(text_value)
|
||||
if isinstance(fn_return, dict):
|
||||
docs = [fn_return]
|
||||
else:
|
||||
try:
|
||||
docs = iter(fn_return)
|
||||
except TypeError:
|
||||
raise click.ClickException("--convert must return dict or iterator")
|
||||
else:
|
||||
docs = (fn(doc) for doc in docs)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue