View Source Backpex.Adapters.Ecto (Backpex v0.8.1)
The Backpex.Adapter
to connect your Backpex.LiveResource
to an Ecto.Schema
.
adapter_config
:repo
(atom/0
) - Required. TheEcto.Repo
that will be used to perform CRUD operations for the given schema.:schema
(atom/0
) - Required. TheEcto.Schema
for the resource.:update_changeset
(function of arity 3) - Required. Changeset to use when updating items. Additional metadata is passed as a keyword list via the third parameter::assigns
- the assigns:target
- the name of theform
target that triggered the changeset call. Default tonil
if the call was not triggered by a form field.
:create_changeset
(function of arity 3) - Required. Changeset to use when creating items. Additional metadata is passed as a keyword list via the third parameter::assigns
- the assigns:target
- the name of theform
target that triggered the changeset call. Default tonil
if the call was not triggered by a form field.
:item_query
(function of arity 3) - The function that can be used to modify the ecto query. It will be used when resources are being fetched. This happens onindex
,edit
andshow
view. In most cases this function will be used to filter items onindex
view based on certain criteria, but it may also be used to join other tables onedit
orshow
view.This function should accept the following parameters:
query
-Ecto.Query.t()
live_action
-atom()
assigns
-map()
It should return an
Ecto.Queryable
. It is recommended to build youritem_query
on top of the incoming query. Otherwise you will likely get binding errors.
Work in progress
The
Backpex.Adapters.Ecto
is under heavy development and will change drastically in future updates. Backpex started out asEcto
-only and we are working on decoupling things to support multiple data sources. This is the first draft of moving allEcto
related functions into a dedicated Ecto adapter.
Summary
Functions
Applies a change to a given item.
Returns the number of items matching the given criteria.
Deletes multiple items.
Gets a database record with the given primary key value.
Gets a database record with the given primary key value.
Inserts given item.
Returns a list of items by given criteria.
Returns the main database query for selecting a list of items by given criteria.
Gets name by schema. This is the last part of the module name as a lowercase atom.
Updates given item.
Updates given items.
Functions
Applies a change to a given item.
Returns the number of items matching the given criteria.
Deletes multiple items.
Gets a database record with the given primary key value.
Returns nil
if no result was found.
Gets a database record with the given primary key value.
Raises Ecto.NoResultsError
if no record was found.
Inserts given item.
Returns a list of items by given criteria.
Returns the main database query for selecting a list of items by given criteria.
TODO: Should be private.
Gets name by schema. This is the last part of the module name as a lowercase atom.
TODO: Make this private once all fields are using the adapter abstractions.
Updates given item.
Updates given items.