Csv2sql – convert comma-separated-values files to sql
Csv2sql class goes deeper into conversion process of csv files, ie:
puts Csv2sql.new("test.csv").to_inserts(:bulk => true)
outputs:
start tramsaction;
insert into test_csv values
(1, "test 1"),
(2, "test 2"),
(3, "test 3"),
(4, "test 4");
commit;
or:
puts Csv2sql.new("account_balances.csv").to_updates([nil, 'balance'], :table => 'accounts')
outputs:
start transaction;
update accounts set balance = "0" where id = "0345S";
update accounts set balance = "3301.37" where id = "0252S";
update accounts set balance = "11903.33" where id = "0345G";
update accounts set balance = "47028.32" where id = "0324G";
...
commit;
You can use optional arguments, ie:
Csv2sql#to_inserts
:bulk - to get bulk inserts
Csv2sql#to_updates:
:before
:after
:row_filter
...
For more details see api docs.
Download
The latest version of Csv2sql can be found at
Documentation can be found at
Installation
The preferred method of installing Csv2sql is through its GEM file. You’ll need to have RubyGems installed for that, though. If you have it, then use:
% [sudo] gem install csv2sql.gem
License
Csv2sql is released under the LGPL license.
Support
The Csv2sql homepage is mirekrusin.com/ruby/csv2sql
For other information, feel free to ask on the ruby-talk mailing list (which is mirrored to comp.lang.ruby) or contact [email protected]