Etso v0.1.0 Etso.Adapter View Source
Used as an Adapter in Repo modules, which transparently spins up one ETS table for each Schema used with the Repo, namespaced to the Repo to allow concurrent running of multiple Repositories.
Link to this section Summary
Functions
Called to autogenerate a value for id/embed_id/binary_id.
Checks out a connection for the duration of the given function.
Deletes a single struct with the given filters.
Returns the dumpers for a given type.
Ensure all applications necessary to run the adapter are started.
Executes a previously prepared query.
Initializes the adapter supervision tree by returning the children and adapter metadata.
Inserts a single new struct in the data store.
Inserts multiple entries into the data store.
Returns the loaders for a given type.
Commands invoked to prepare a query for all
, update_all
and delete_all
.
Streams a previously prepared query.
Updates a single struct with the given filters.
Link to this section Functions
Called to autogenerate a value for id/embed_id/binary_id.
Returns the autogenerated value, or nil if it must be autogenerated inside the storage or raise if not supported.
Callback implementation for Ecto.Adapter.Schema.autogenerate/1
.
Checks out a connection for the duration of the given function.
In case the adapter provides a pool, this guarantees all of the code
inside the given fun
runs against the same connection.
Callback implementation for Ecto.Adapter.checkout/3
.
Deletes a single struct 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) be given as a filter. Therefore,
in case there is no record matching the given filters,
{:error, :stale}
is returned.
Callback implementation for Ecto.Adapter.Schema.delete/4
.
Returns the dumpers for a given type.
It receives the primitive type and the Ecto type (which may be primitive as well). It returns a list of dumpers with the given type usually at the beginning.
This allows developers to properly translate values coming from the Ecto into adapter ones. For example, if the database does not support booleans but instead returns 0 and 1 for them, you could add:
def dumpers(:boolean, type), do: [type, &bool_encode/1]
def dumpers(_primitive, type), do: [type]
defp bool_encode(false), do: {:ok, 0}
defp bool_encode(true), do: {:ok, 1}
All adapters are required to implement a clause for :binary_id types,
since they are adapter specific. If your adapter does not provide
binary ids, you may simply use Ecto.UUID
:
def dumpers(:binary_id, type), do: [type, Ecto.UUID]
def dumpers(_primitive, type), do: [type]
Callback implementation for Ecto.Adapter.dumpers/2
.
Ensure all applications necessary to run the adapter are started.
Callback implementation for Ecto.Adapter.ensure_all_started/2
.
Executes a previously prepared query.
It must return a tuple containing the number of entries and
the result set as a list of lists. The result set may also be
nil
if a particular operation does not support them.
The adapter_meta
field is a map containing some of the fields found
in the Ecto.Query
struct.
Callback implementation for Ecto.Adapter.Queryable.execute/5
.
Initializes the adapter supervision tree by returning the children and adapter metadata.
Callback implementation for Ecto.Adapter.init/1
.
insert(adapter_meta, schema_meta, fields, on_conflict, returning, options)
View SourceInserts a single new struct in the data store.
Autogenerate
The primary key will be automatically included in returning
if the
field has type :id
or :binary_id
and no value was set by the
developer or none was autogenerated by the adapter.
Callback implementation for Ecto.Adapter.Schema.insert/6
.
insert_all(adapter_meta, schema_meta, header, entries, on_conflict, returning, options)
View SourceInserts multiple entries into the data store.
In case an Ecto.Query
given as any of the field values by the user,
it will be sent to the adapter as a tuple with in the shape of
{query, params}
.
Callback implementation for Ecto.Adapter.Schema.insert_all/7
.
Returns the loaders for a given type.
It receives the primitive type and the Ecto type (which may be primitive as well). It returns a list of loaders with the given type usually at the end.
This allows developers to properly translate values coming from the adapters into Ecto ones. For example, if the database does not support booleans but instead returns 0 and 1 for them, you could add:
def loaders(:boolean, type), do: [&bool_decode/1, type]
def loaders(_primitive, type), do: [type]
defp bool_decode(0), do: {:ok, false}
defp bool_decode(1), do: {:ok, true}
All adapters are required to implement a clause for :binary_id
types,
since they are adapter specific. If your adapter does not provide binary
ids, you may simply use Ecto.UUID
:
def loaders(:binary_id, type), do: [Ecto.UUID, type]
def loaders(_primitive, type), do: [type]
Callback implementation for Ecto.Adapter.loaders/2
.
Commands invoked to prepare a query for all
, update_all
and delete_all
.
The returned result is given to execute/6
.
Callback implementation for Ecto.Adapter.Queryable.prepare/2
.
Streams a previously prepared query.
It returns a stream of values.
The adapter_meta
field is a map containing some of the fields found
in the Ecto.Query
struct.
Callback implementation for Ecto.Adapter.Queryable.stream/5
.
update(adapter_meta, schema_meta, fields, filters, returning, options)
View SourceUpdates a single struct 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) be given as a filter. Therefore,
in case there is no record matching the given filters,
{:error, :stale}
is returned.
Callback implementation for Ecto.Adapter.Schema.update/6
.