#csv #sql #cli

app c2s

SQL generate tool from csv

3 unstable releases

0.2.0 Dec 30, 2022
0.1.1 Dec 29, 2022
0.1.0 Dec 29, 2022

#2603 in Command line utilities

MIT license

8KB
116 lines

c2s

CSVファイルから、SQLのINSERT文をgenerateするツール

How to install

install via cargo

cargo install c2s

How to use

以下のようなデータを持つ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 );
  • ファイル名: テーブル名として扱われます。
  • 1行目: カラム名として扱われます。
  • 明示的に 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 );

Dependencies

~2.5–3.5MB
~53K SLoC