475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
|
# File 'lib/mass_record.rb', line 475
def insert hashes, into:nil
begin
return false if hashes.blank? or into.blank?
logger.debug "Insert #{into.to_s}>".black.on_white
hashes = [hashes] unless hashes.is_a? Array
model = get_model from:into
errors = []
hashes.each do |hash|
sql = sql_for_insert hash, into:model
begin
query sql, connection:model
self.individual_count += 1
logger << ".".black.on_white if logger.debug?
rescue Exception => e
logger.debug e.message
logger << 'E'.black.on_white if logger.info?
errors << IndividualError.new(e,table:into,operation:"insert",json_object:hash)
end
end
return errors
rescue Exception => e
return (defined? errors) ? (errors << IndividualError.new(e, table:into, operation:"insert")) : [IndividualError.new( e, table:into, operation:"insert")]
end
end
|