mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-24 01:44:31 +02:00
sqlite-utils memory --flatten, closes #332
This commit is contained in:
parent
13195d8747
commit
12b8c9de25
3 changed files with 29 additions and 1 deletions
|
|
@ -1190,6 +1190,7 @@ def query(
|
|||
multiple=True,
|
||||
help="Additional databases to attach - specify alias and filepath",
|
||||
)
|
||||
@click.option("--flatten", is_flag=True, help="Flatten nested JSON objects")
|
||||
@output_options
|
||||
@click.option("-r", "--raw", is_flag=True, help="Raw output, first column of first row")
|
||||
@click.option(
|
||||
|
|
@ -1226,6 +1227,7 @@ def memory(
|
|||
paths,
|
||||
sql,
|
||||
attach,
|
||||
flatten,
|
||||
nl,
|
||||
arrays,
|
||||
csv,
|
||||
|
|
@ -1300,6 +1302,8 @@ def memory(
|
|||
if format_used in (Format.CSV, Format.TSV) and not no_detect_types:
|
||||
tracker = TypeTracker()
|
||||
rows = tracker.wrap(rows)
|
||||
if flatten:
|
||||
rows = (dict(_flatten(row)) for row in rows)
|
||||
db[csv_table].insert_all(rows, alter=True)
|
||||
if tracker is not None:
|
||||
db[csv_table].transform(types=tracker.types)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue