6
7
8
9
10
11
12
13
14
15
|
# File 'lib/dl_jusyo_jp/import.rb', line 6
def self.execute
CSV.foreach(Download.csv.path, encoding: "Shift_JIS:UTF-8", write_headers: false).each_slice(chunk_size) do |rows|
insert = "INSERT INTO #{DlJusyoJp::ADDRESS_DOWNLOAD_TABLE} VALUES "
values = rows.map do |row|
next unless row[0].match(/^\d+$/)
'(NULL,' + row.map{|col| "'#{col}'"}.join(',') + ')'
end.compact.join(',')
ActiveRecord::Base.connection.exec_insert("#{insert}#{values}", 'jusyo.jp bulk insert', [])
end
end
|