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. The Ecto.Repo that will be used to perform CRUD operations for the given schema.

  • :schema (atom/0) - Required. The Ecto.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 the form target that triggered the changeset call. Default to nil 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 the form target that triggered the changeset call. Default to nil 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 on index, edit and show view. In most cases this function will be used to filter items on index view based on certain criteria, but it may also be used to join other tables on edit or show 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 your item_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 as Ecto-only and we are working on decoupling things to support multiple data sources. This is the first draft of moving all Ecto 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.

Functions

Link to this function

apply_criteria(query, criteria, fields)

View Source
Link to this function

apply_filters(query, filters, empty_filter_key)

View Source
Link to this function

apply_search(query, schema, full_text_search, arg)

View Source
Link to this function

change(item, attrs, fields, assigns, config, opts)

View Source

Applies a change to a given item.

Link to this function

count(fields, assigns, config, criteria \\ [])

View Source

Returns the number of items matching the given criteria.

Link to this function

delete_all(items, live_resource)

View Source

Deletes multiple items.

Link to this function

get(primary_value, assigns, live_resource)

View Source

Gets a database record with the given primary key value.

Returns nil if no result was found.

Link to this function

get!(primary_value, assigns, live_resource)

View Source

Gets a database record with the given primary key value.

Raises Ecto.NoResultsError if no record was found.

Link to this function

get_primary_key_field(schema)

View Source

Inserts given item.

Link to this function

list(fields, assigns, config, criteria \\ [])

View Source

Returns a list of items by given criteria.

Link to this function

list_query(assigns, item_query, fields, criteria \\ [])

View Source

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.

Link to this function

update_all(items, updates, live_resource)

View Source

Updates given items.

Link to this function

validate_config!(config)

View Source