postgresql - Mass instantiate or build objects in ActiveRecord quickly in Ruby -


i have financial app generates dynamic data database. projected daily revenue numbers, example, generated , outputted sql records (pg:result in postgresql 9.4). how instantiate or build thousands of activerecord objects quickly? loop through each sql record taking long.

note not database issue, because not need save database (in case mass insertion sql statement work). these numbers dynamic don't have create , save objects. reason want build activerecord objects can sort , filter through numbers using ar methods such where , find (for example, sorting objects sheet id and/or date). noticed keeping pg:result saves time, sorting through results (which array of hashes) requires messy code. sample object, flow, below:

flow.new   value_subunit: 10,   sheet_id: 1,   is_actual: true,   period_start: '2015-01-01' end 

the sql query output looks following:

sheet_id  value_subunit is_actual period_start ---------------------------------------------- 1         10            1         '2015-01-01' 2         20            0         '2015-02-01' 

try activerecord-import. blog talks it: https://blog.codeship.com/speed-up-activerecord/


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -