Blink.Adapter behaviour (blink v0.6.1)

View Source

Defines 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

call(rows, table_name, repo, opts)

@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

copy_to_table(rows, table_name, repo, opts \\ [])

@spec copy_to_table(
  rows :: Enumerable.t(),
  table_name :: String.t(),
  repo :: Ecto.Repo.t(),
  opts :: Keyword.t()
) :: :ok