AshBackpex.Adapter (Ash Backpex v0.0.3)

View Source
  use Backpex.LiveResource,
    adapter: InsiWeb.BackpexAshAdapter,
    adapter_config: [
      resource: User,
      schema: User,
      repo: Insi.Repo,
      create_action: :create_with_plaintext_pwd,
      create_changeset: &InsiWeb.BackpexAshAdapter.create_changeset/3,
      update_changeset: &InsiWeb.BackpexAshAdapter.update_changeset/3,
      load: &InsiWeb.BackpexAshAdapter.load/3
    ],
    layout: {InsiWeb.Layouts, :admin}

You can specify a default create_action or update_action, which must refer to an action on the resource.

You must specify the create_changeset, update_changeset, and load functions because for some reason Backpex is not respecting the provided default Nimble values. Override them in your resource if necessary.

The Backpex.Adapter to connect your Backpex.LiveResource to an Ash.Resource.

## adapter_config

  • :resource (atom/0) - Required. The Ash.Resource that will be used to perform CRUD operations.

  • :schema (atom/0) - Required. The Ash.Resource for the resource.

  • :repo (atom/0) - Required. The Ecto.Repo that will be used to perform CRUD operations for the given schema.

  • :create_action (atom/0) - The resource action to use when creating new items in the admin. Defaults to the primary create action.

  • :read_action (atom/0) - The resource action to use when reading items in the admin. Defaults to the primary read action.

  • :update_action (atom/0) - The resource action to use when updating items in the admin. Defaults to the primary update action.

  • :destroy_action (atom/0) - The resource action to use when destroying items in the admin. Defaults to the primary destroy action.

  • :create_changeset (function of arity 3) - 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. The default value is &AshBackpex.Adapter.create_changeset/3.
  • :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. The default value is &AshBackpex.Adapter.update_changeset/3.
  • :load (function of arity 3) - Relationships, calculations and aggregates that Ash should load

    • [comments: [:author]] The default value is &AshBackpex.Adapter.load/3.

    Work in progress

    The Backpex.Adapters.Ash is currently not usable! It can barely list and show items. We will work on this as we continue to implement the Backpex.Adapter pattern throughout the codebase.

Summary

Functions

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

Applies a change to a given item.

count(criteria, assigns, live_resource)

Returns the number of items matching the given criteria.

create_changeset(item, params, assigns)

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.

insert(changeset, live_resource)

Inserts given item.

list(criteria, assigns, live_resource)

Returns a list of items by given criteria.

load(_, _, _)

update(changeset, live_resource)

Updates given item.

update_all(items, updates, live_resource)

Updates given items.

update_changeset(item, params, assigns)

validate_config!(config)