Handles import of records from remote sender with conflict resolution.
This module is responsible for importing records received from a sender into the local database, handling primary key conflicts according to the configured strategy.
Conflict Strategies
:skip- Skip import if record with same primary key exists (default):overwrite- Replace existing record with imported data:merge- Merge imported data with existing record (keeps existing values where new is nil):append- Always insert as new record with auto-generated ID (ignores source primary key)
Usage
# Import a batch of records with a strategy
{:ok, result} = DataImporter.import_records("users", records, :skip)
# Result structure:
%{
created: 5,
updated: 2,
skipped: 3,
errors: []
}
Summary
Functions
Imports records for multiple tables in a single operation.
Imports a batch of records into the specified table.
Types
@type conflict_strategy() :: :skip | :overwrite | :merge | :append
@type import_result() :: %{ created: non_neg_integer(), updated: non_neg_integer(), skipped: non_neg_integer(), errors: list() }
Functions
Imports records for multiple tables in a single operation.
Parameters
table_records- Map of table name to records liststrategies- Map of table name to conflict strategy
Returns
{:ok, %{table_name => result}}
@spec import_records(String.t(), [map()], conflict_strategy()) :: {:ok, import_result()} | {:error, term()}
Imports a batch of records into the specified table.
Parameters
table- The table name to import intorecords- List of record maps from the senderstrategy- Conflict resolution strategy (:skip,:overwrite,:merge,:append)
Returns
{:ok, result}with counts and any errors{:error, reason}if import fails completely