mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-28 12:54:15 +02:00
Add --convert example to sqlite-utils insert --help, closes #404
This commit is contained in:
parent
3acc2f1772
commit
79a5ece62e
2 changed files with 23 additions and 0 deletions
|
|
@ -208,6 +208,17 @@ See :ref:`cli_inserting_data`, :ref:`cli_insert_csv_tsv`.
|
||||||
Your Python code will be passed a "row" variable representing the imported
|
Your Python code will be passed a "row" variable representing the imported
|
||||||
row, and can return a modified row.
|
row, and can return a modified row.
|
||||||
|
|
||||||
|
This example uses just the name, latitude and longitude columns from a CSV
|
||||||
|
file, converting name to upper case and latitude and longitude to floating
|
||||||
|
point numbers:
|
||||||
|
|
||||||
|
sqlite-utils insert plants.db plants plants.csv --csv --convert '
|
||||||
|
return {
|
||||||
|
"name": row["name"].upper(),
|
||||||
|
"latitude": float(row["latitude"]),
|
||||||
|
"longitude": float(row["longitude"]),
|
||||||
|
}'
|
||||||
|
|
||||||
If you are using --lines your code will be passed a "line" variable, and for
|
If you are using --lines your code will be passed a "line" variable, and for
|
||||||
--text an "text" variable.
|
--text an "text" variable.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1144,6 +1144,18 @@ def insert(
|
||||||
Your Python code will be passed a "row" variable representing the
|
Your Python code will be passed a "row" variable representing the
|
||||||
imported row, and can return a modified row.
|
imported row, and can return a modified row.
|
||||||
|
|
||||||
|
This example uses just the name, latitude and longitude columns from
|
||||||
|
a CSV file, converting name to upper case and latitude and longitude
|
||||||
|
to floating point numbers:
|
||||||
|
|
||||||
|
\b
|
||||||
|
sqlite-utils insert plants.db plants plants.csv --csv --convert '
|
||||||
|
return {
|
||||||
|
"name": row["name"].upper(),
|
||||||
|
"latitude": float(row["latitude"]),
|
||||||
|
"longitude": float(row["longitude"]),
|
||||||
|
}'
|
||||||
|
|
||||||
If you are using --lines your code will be passed a "line" variable,
|
If you are using --lines your code will be passed a "line" variable,
|
||||||
and for --text an "text" variable.
|
and for --text an "text" variable.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue