Write-back cache (lazy write) and ActiveRecord

There are afaik several ways to do multi-record operations on DB. Mileage of course varies depending on DMBS.

Is AR capable of folding multi-record modifications (inserts, deletes or updates) to single SQL statement? Interface I had in mid was something like

  with_lazy_write do     massive_data.each { |item| MyModel.create_from(item) }   end

which (depending on DB adapter) could boil down to something like these

  INSERT INTO my_models SELECT ... UNION SELECT ... UNION SELECT ...   INSERT INTO my_models VALUES (...), (...), (...), (...), (...), ...

There are afaik several ways to do multi-record operations on DB. Mileage of course varies depending on DMBS.

Is AR capable of folding multi-record modifications (inserts, deletes or updates) to single SQL statement? Interface I had in mid was something like

Not that I know of.

Fred

Am I missing something or am I just the only one who needs to optimize multi-record modifications? :slight_smile:

For bulk inserts there's ar-extensions.

Here's a blog post: http://rubypond.com/articles/2008/06/18/bulk-insertion-of-data-with-activerecord/