Blink.Adapter behaviour (blink v0.6.1)
View SourceDefines the adapter behaviour and dispatches to the selected adapter.
Adapters are responsible for implementing database-specific bulk insert
operations. Each adapter must implement the call/4 callback to bulk insert
rows into a table using a database-specific mechanism (e.g., PostgreSQL's COPY
command).
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
run(seeder, MyApp.Repo, adapter: MyApp.CustomAdapter)
# Or via copy_to_table/4
Blink.copy_to_table(items, "users", MyApp.Repo, adapter: MyApp.CustomAdapter)
Summary
Callbacks
Performs a bulk copy operation to insert rows into a database table.
Callbacks
@callback call( rows :: Enumerable.t(), table_name :: String.t(), repo :: Ecto.Repo.t(), opts :: Keyword.t() ) :: :ok
Performs a bulk copy operation to insert rows into a database table.
Parameters
rows- 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( rows :: Enumerable.t(), table_name :: String.t(), repo :: Ecto.Repo.t(), opts :: Keyword.t() ) :: :ok