View Source Backpex.Adapters.Ecto (Backpex v0.9.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

apply_criteria(query, criteria, fields)

apply_filters(query, filters, empty_filter_key)

apply_search(query, schema, full_text_search, arg)

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

Applies a change to a given item.

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

Returns the number of items matching the given criteria.

delete_all(items, live_resource)

Deletes multiple items.

get(primary_value, assigns, live_resource)

Gets a database record with the given primary key value.

Returns nil if no result was found.

get!(primary_value, assigns, live_resource)

Gets a database record with the given primary key value.

Raises Ecto.NoResultsError if no record was found.

get_primary_key_field(schema)

insert(item, config)

Inserts given item.

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

Returns a list of items by given criteria.

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

Returns the main database query for selecting a list of items by given criteria.

TODO: Should be private.

name_by_schema(schema)

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.

update(item, config)

Updates given item.

update_all(items, updates, live_resource)

Updates given items.

validate_config!(config)