How to combine multiple UPDATE statements?

I’d like to update many records more efficiently. UPSERT is not an option since we’re not using PostgreSQL at the moment. The problem is that every UPDATE statement only affects one row, so every row needs its own statement. Is there any way for me to pass multiple UPDATE to ROM so it can combine them or at least execute them in batch?

I’m doing it like this currently:

class CreateParameters < ROM::Changeset::Create
  map do |item|
    {
      path:  item.path,
      value: item.value,
    }
  end
end

class UpdateParameters < ROM::Changeset::Update
  map do |item|
    {
      path:  item.path,
      value: item.value,
    }
  end
end

def store_parameters(items)
  parameters.transaction do
    existing             = existing_paths(items).to_set
    to_update, to_create = items.partition { |item| existing.include? item.path }

    parameters.changeset(CreateParameters, to_create).commit unless to_create.empty?

    # NOTE: bottleneck here
    to_update.each do |item|
      parameters.where(path: item.path).changeset(UpdateParameters, item).commit
    end
  end
end

There’s no public API for that at the moment. We may add it in the future though. In the meantime you can handle it manually using the underlying Sequel API.