lib/arison/core.rb in arison-0.1.1 vs lib/arison/core.rb in arison-0.1.3

- old
+ new

@@ -1,21 +1,24 @@ require 'active_record' require 'activerecord-import' require 'active_support' +require 'logger' +require 'pp' module Arison class Core def initialize(profile) @profile = profile ActiveRecord::Base.establish_connection(@profile) ActiveRecord::Base.default_timezone = :local @connection = ActiveRecord::Base.connection + @logger = Logger.new(STDOUT) end def query(sql) - @connection.exec_query(sql).to_a + @connection.exec_query(sql).to_a end def columns_with_table_name(table_name) columns(get_class(table_name)) end @@ -37,11 +40,17 @@ data.each do |record| instance = klass.new begin record = record.inject({}){ |result, (k, v)| length = limits[k] - result[k] = (length.nil? || v.nil? || v.class != String) ? v : v.slice(0, length) + result[k] = if (v.class == Array || v.class == Hash) + v.to_s + elsif (length.nil? || v.nil? || v.class != String) + v + else + v.slice(0, length) + end result } instance.attributes = record rescue ActiveRecord::UnknownAttributeError => e rescue => e @@ -49,10 +58,16 @@ ensure instances << instance end end instances.in_groups_of(10000, false) do |block| - klass.import(block) + begin + klass.import(block) + rescue => e + pp block + @logger.error "\n#{e.message}\n#{e.backtrace.join("\n")}" + raise + end end end def get_create_table_dsl(table_name, hash) dsl = %Q{