#csv #sql #cli

app c2s

从 CSV 生成 SQL 插入语句的工具

3 个不稳定版本

0.2.0 2022 年 12 月 30 日
0.1.1 2022 年 12 月 29 日
0.1.0 2022 年 12 月 29 日

#226 in #csv

MIT 许可协议

8KB
116

c2s

从 CSV 文件生成 SQL INSERT 语句的工具

安装方法

通过 cargo 安装

cargo install c2s

使用方法

假设有一个包含以下数据的 CSV 文件,名为 users.csv:

user_id,email,user_name,height,weight,birthday
1,a@example.com,太郎,172.5,null,2022-05-05
2,b@example.com,二郎,182.3,92.03,null

输出如下。

$ c2s users.csv
INSERT INTO users ( user_id, email, user_name, height, weight, birthday ) VALUES ( 1, 'a@example.com', '太郎', 172.5, null, '2022-05-05' );
INSERT INTO users ( user_id, email, user_name, height, weight, birthday ) VALUES ( 2, 'b@example.com', '二郎', 182.3, 92.03, null );
  • 文件名:用作表名。
  • 第一行:用作列名。
  • 明确定义为 null 的内容将被输出为 null。没有内容的地方,如 tanaka,,65.0 这样的部分将被输出为 VALUES ( ...,'tanaka','',65.0 )

您也可以显式指定表名。

$ c2s users.csv demo_users
INSERT INTO demo_users ( user_id, email, user_name, height, weight, birthday ) VALUES ( 1, 'a@example.com', '太郎', 172.5, null, '2022-05-05' );
INSERT INTO demo_users ( user_id, email, user_name, height, weight, birthday ) VALUES ( 2, 'b@example.com', '二郎', 182.3, 92.03, null );

依赖项

~2.3–3MB
~50K SLoC