Ecto.Adapter behaviour

This module specifies the adapter API that an adapter is required to implement.

Source

Types

t :: module

source :: binary

returning :: [atom]

autogenerate_id :: {field :: atom, type :: :id | :binary_id, value :: term} | nil

Callbacks

all/4

Specs:

  • all(repo, query :: Ecto.Query.t, params :: list, options) :: [[term]] | no_return

Fetches all results from the data store based on the given query.

Source
delete/5

Specs:

Deletes a sigle model with the given filters.

While filters can be any record column, it is expected that at least the primary key (or any other key that uniquely identifies an existing record) to be given as filter. Therefore, in case there is no record matching the given filters, {:error, :stale} is returned.

Autogenerate

The autogenerate_id tells if there is an autogenerated primary key and if so, its name type and value. The type is :id or :binary_id and the adapter should raise if it cannot handle those types.

If the value is nil, it means there is no autogenerate primary key.

Source
delete_all/4

Specs:

Deletes all entities matching the given query.

The query shall only have where expressions and a from expression. Returns the number of affected entities.

Source
id_types/1

Specs:

Returns the binary id type for this adapter.

If the database adapter does not support provide binary id functionality, Ecto.UUID is recommended.

Source
insert/6

Specs:

Inserts a single new model in the data store.

Autogenerate

The autogenerate_id tells if there is a primary key to be autogenerated and, if so, its name, type and value. The type is :id or :binary_id and the adapter should raise if it cannot handle those types.

If the value is nil, it means no value was supplied by the user and the database MUST return a new one.

autogenerate_id also allows drivers to detect if a value was assigned to a primary key that does not support assignment. In this case, value will be a non nil value.

Source
start_link/2

Specs:

  • start_link(repo, options) :: {:ok, pid} | :ok | {:error, {:already_started, pid}} | {:error, term}

Starts any connection pooling or supervision and return {:ok, pid} or just :ok if nothing needs to be done.

Returns {:error, {:already_started, pid}} if the repo already started or {:error, term} in case anything else goes wrong.

Source
stop/1

Specs:

  • stop(repo) :: :ok

Stops any connection pooling or supervision started with start_link/1.

Source
update/7

Specs:

Updates a single model with the given filters.

While filters can be any record column, it is expected that at least the primary key (or any other key that uniquely identifies an existing record) to be given as filter. Therefore, in case there is no record matching the given filters, {:error, :stale} is returned.

Autogenerate

The autogenerate_id tells if there is an autogenerated primary key and if so, its name type and value. The type is :id or :binary_id and the adapter should raise if it cannot handle those types.

If the value is nil, it means there is no autogenerate primary key.

autogenerate_id also allows drivers to detect if a value was assigned to a primary key that does not support assignment. In this case, value will be a non nil value.

Source
update_all/5

Specs:

  • update_all(repo, query :: Ecto.Query.t, updates :: Keyword.t, params :: list, options) :: integer | no_return

Updates all entities matching the given query with the values given. The query shall only have where expressions and a single from expression. Returns the number of affected entities.

Source