Selecto.DB.Adapter behaviour (Selecto v0.3.12)

Behaviour contract for Selecto database adapters.

Adapter modules are responsible for:

  • establishing a connection handle from adapter-specific options,
  • executing SQL with bound params,
  • providing adapter placeholder strategy,
  • quoting identifiers when needed by adapter-specific tooling, and
  • declaring coarse feature support.

Streaming contract:

  • supports?(:stream) should return true only when stream/4 is implemented and can produce rows for the given connection context.
  • stream/4 is optional; adapters that do not support streaming should omit it and return false for supports?(:stream).

Link to this section Summary

Link to this section Types

Link to this type

connection()

@type connection() :: term()
Link to this type

connection_options()

@type connection_options() :: keyword() | map() | term()
Link to this type

execute_options()

@type execute_options() :: keyword()
@type params() :: [term()]
@type query() :: String.t() | iodata()
@type result() :: %{rows: list(), columns: [String.t()]}
Link to this type

stream_result()

@type stream_result() ::
  {:ok, Enumerable.t()} | {:ok, Enumerable.t(), [String.t()]} | {:error, term()}

Link to this section Callbacks

Link to this callback

connect(connection_options)

@callback connect(connection_options()) :: {:ok, connection()} | {:error, term()}
Link to this callback

execute(connection, query, params, execute_options)

@callback execute(connection(), query(), params(), execute_options()) ::
  {:ok, result()} | {:error, term()}
@callback name() :: atom()
Link to this callback

placeholder(pos_integer)

@callback placeholder(pos_integer()) :: iodata()
Link to this callback

quote_identifier(t)

@callback quote_identifier(String.t()) :: String.t()
Link to this callback

stream(connection, query, params, execute_options)

(optional)
@callback stream(connection(), query(), params(), execute_options()) :: stream_result()
Link to this callback

supports?(atom)

@callback supports?(atom()) :: boolean()