csv-to-sqlite 2.1 - script support, encodings and brackets
Version 2.1 of csv-to-sqlite was just released.
There are a few new things, suggested in GitHub issues: you can now specify that you do not want brackets around your column names, you can specify the encoding your files (the default still is UTF-8) and it's now easier to use csv-to-sqlite in scripts.
If you wish to do that, simply install it as a dependency:
pip install csv-to-sqlite
Then import it and call write_csv()
.
import csv_to_sqlite
# all the usual options are supported
options = csv_to_sqlite.CsvOptions(typing_style="full", encoding="windows-1250")
input_files = ["abilities.csv", "moves.csv"] # pass in a list of CSV files
csv_to_sqlite.write_csv(input_files, "output.sqlite", options)
And that's it.
As usual, if you want to see what you can do, call csv-to-sqlite --help
. The current list is:
Usage: csv-to-sqlite [OPTIONS]
A script that processes the input CSV files and copies them into a SQLite
database. Each file is copied into a separate table. Column names are
taken from the headers (first row) in the csv file.
If file names are passed both via the --file option and standard input,
all of them are processed.
For example in PowerShell, if you want to copy all the csv files in the
current folder into a database called "out.db", type:
ls *.csv | % FullName | csv-to-sqlite -o out.db
Options:
-f, --file PATH A file to copy into the database. Can be
specified multiple times. All the files are
processed, including file names piped from
standard input.
-o, --output PATH The output database path
-t, --typing [full|quick|none] Determines whether the script should guess
the column type (int/float/string
supported). quick: only base the types on
the first line full: read the entire file
none: no typing, every column is string
-D, --drop-tables / --no-drop-tables
Determines whether the tables should be
dropped before creation, if they already
exist (BEWARE OF DATA LOSS)
-v, --verbose Determines whether progress reporting
messages should be printed
-x, --delimiter TEXT Choose the CSV delimiter. Defaults to comma.
Hint: for tabs, in Bash use $'\t'.
-e, --encoding TEXT Choose the input CSV's file encoding. Use
the string identifier Python uses to specify
encodings, e.g. 'windows-1250'.
--bracket-style [all|none] Determines whether all the column names
should be wrapped in brackets, or none of
them should be. Keep in mind that if you
select 'none', it is up to you to ensure the
CSV's column names are also valid SQLite
column names.
all: wrap all. none: no brackets
--help Show this message and exit.
Comments ()