go install github.com/seipan/csql@latest
command option
Usage:
csql [flags]
Flags:
-c, --check check csv format
-d, --dsn string DSN for Connecting Database
-h, --help help for csql
-p, --path string FilePath for Parsing CSVFile
-q, --query output query
-t, --type string Database Type
Type, DSN, and path can be specified not only from command-line arguments but also from the .csql.yaml file. Below is an example.
type: mysql
dsn: hogehoge
filepath: ./test.csv
dsn represents the Data Source Name of the database into which you want to insert CSV data.
path represents the file path of the CSV you want to analyze this time.
type represents the type of the database. Currently, it supports mariaDB, mysql, postgres, and sqlite3.
if success patern
csql --check --path=./testdata/csv/test01.csv --type=mysql --dsn=hogehoge
___________ ____ __
/ ____/ ___// __ \ / /
/ / \__ \/ / / / / /
/ /___ ___/ / /_/ / / /___
\____//____/\___\_\/_____/
csv format is correct
failed pattern
csql --check --path=./testdata/csv/test02.csv --type=mysql --dsn=hogehoge
___________ ____ __
/ ____/ ___// __ \ / /
/ / \__ \/ / / / / /
/ /___ ___/ / /_/ / / /___
\____//____/\___\_\/_____/
csv format is incorrect : table name is empty
exit status 1
csql --query --path=./testdata/csv/test01.csv --type=mysql --dsn="hoge:hoge@tcp(hoge:3306)/hoge?charset=utf8&parseTime=true"
___________ ____ __
/ ____/ ___// __ \ / /
/ / \__ \/ / / / / /
/ /___ ___/ / /_/ / / /___
\____//____/\___\_\/_____/
INSERT INTO user (name, id, email) VALUES (?, ?, ?)
csql --path=./testdata/csv/test01.csv --type=mysql --dsn="hoge:hoge@tcp(localhost:3308)/hoge?parseTime=true&collation=utf8mb4_bin"
___________ ____ __
/ ____/ ___// __ \ / /
/ / \__ \/ / / / / /
/ /___ ___/ / /_/ / / /___
\____//____/\___\_\/_____/
insert 2 rows
Inserting: | 100%%
Code licensed under the MIT License.