Blink.Adapter behaviour (blink v0.5.1)
View SourceBehaviour and routing for Blink database adapters.
Adapters are responsible for implementing database-specific bulk insert
operations. Each adapter must implement the call/4 callback which performs
the bulk insertion using the appropriate database-specific mechanism (e.g.,
PostgreSQL's COPY, MySQL's LOAD DATA INFILE, etc.).
Example
defmodule MyApp.CustomAdapter do
@behaviour Blink.Adapter
@impl true
def call(items, table_name, repo, opts) do
# Custom bulk copy implementation
:ok
end
end
# Usage
Blink.copy_to_table(items, "users", MyApp.Repo, adapter: MyApp.CustomAdapter)
Summary
Callbacks
Performs a bulk copy operation to insert items into a database table.
Functions
Copies a list of items into a database table using the appropriate database adapter.
Callbacks
@callback call( items :: Enumerable.t(), table_name :: String.t(), repo :: Ecto.Repo.t(), opts :: Keyword.t() ) :: :ok
Performs a bulk copy operation to insert items into a database table.
Parameters
items- An enumerable (list or stream) of maps where each map represents a row to insert. All maps must have the same keys, which correspond to the table columns.table_name- The name of the table to insert into (string).repo- An Ecto repository module.opts- Keyword list of adapter-specific options.
Returns
:ok- When the copy operation succeeds
Raises an exception when the copy operation fails.
Functions
@spec copy_to_table( items :: Enumerable.t(), table_name :: String.t(), repo :: Ecto.Repo.t(), opts :: Keyword.t() ) :: :ok
Copies a list of items into a database table using the appropriate database adapter.
The adapter is selected based on the :adapter option in opts.