简体   繁体   English

RoR-使用smarterCSV gem将csv导入MySQL DB

[英]RoR - import csv to MySQL DB with smarterCSV gem

I'm trying to upload a csv file with a lot of posible clients (15000) on a MySQL table. 我正在尝试在MySQL表上上传带有许多可能的客户端(15000)的csv文件。 I want to keep on a table for later retrieve info, complete forms and make users. 我想保留一张桌子,以便以后检索信息,填写表格并吸引用户。

Now i'm on the beginning, trying to import the csv to the MySQL. 现在我开始,尝试将csv导入MySQL。

I read some solutions that takes smarterCSV gem , so i must do a migration with the db structure and then execute the rake task or not needed to execute the migration for this? 我阅读了一些使用smarterCSV gem的解决方案,因此我必须使用db结构进行迁移,然后执行rake任务,还是不需要为此执行迁移?

The kind of code i want to use for import the csv is something like i read on before posts like Ruby on Rails - Import Data from a CSV file 我想用于导入csv的代码类型类似于在Ruby on Rails之类的文章-从CSV文件导入数据之前阅读的内容

require 'smarter_csv'
  options = {}
  SmarterCSV.process('input_file.csv', options) do |chunk|
    chunk.each do |data_hash|
      Moulding.create!( data_hash )
    end
  end

You may use my importer gem. 您可以使用我的进口商宝石。 It also uses SmarterCSV. 它还使用SmarterCSV。

https://github.com/michaelnera/active_record_importer https://github.com/michaelnera/active_record_importer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM