module ReeDao::DatasetExtensions::InstanceMethods

def import_all(entities, batch_size: IMPORT_BATCH_SIZE)

def import_all(entities, batch_size: IMPORT_BATCH_SIZE)
  return if entities.empty?
  mapper = opts[:schema_mapper]
  columns = columns
  raw = {}
  columns.delete(:id)
  columns.delete(:row)
  data = entities.map do |entity|
    hash = mapper.to_hash(entity)
    raw[entity] = hash
    columns.map { hash[_1] }
  end
  ids = import(
    columns, data, slice: batch_size, return: :primary_key
  )
  ids.each_with_index do |id, index|
    entity = entities[index]
    raw_data = raw[entity]
    set_entity_primary_key(entity, raw_data, id)
    set_persistence_state(entity, raw_data)
  end
  nil
end