CSV2SQL 发布第一个测试版


具体的使用说明,可以参照项目的 README 文档,我这里再贴一下。

How to use

  1. Prepare the xlsx file with your data

Assume the file is dropped into test/import.xlsx, you can download it from here

  1. Config the .yml

注意,此处,代码被 WordPress 自动转义了。

Note, there are more than one joint config with name: convert_sql, which means you can import multi data sheet with different config,
in this example the second convert_sql joint has been disabled, you can enable it if you wish, and also you can add more convert_sql joints.

And also as you can see, in the first convert_sql joint, with the data sheet fish_information, the config row_format is a array,
and have more than one SQL template, separated with ; , which means you can generate multi SQL from one single data sheet,
map one data row to multi data records, and then we can inset the data into different tables.

The config row_format is a SQL template, and the config column_name is how your data sheet will be used in your template,
like this template variable <{is_homemade: }>, it will looking for the data from column is_homemade which we have already configured in section column_name,
you can get the SQL template by using MySQLWorkBench quickly([select db]->[select table]->[Copy to Clipboard]->[Insert Statement])

Note, once you change the column in data sheet, you must keep the column_name updated.

Note, please also change MySQL connection in joint mysql_conn config, ie: your_mysql_user:you_password@tcp(your_mysql_host:3306)/your_mysql_db?charset=utf8

And, the example is jus a example, you can use it to map any data sheet to any mysql table, update the config and import the data.

  1. Start to import the data

  1. Now, check out the database, you will see 2 new records in two different table