# `Backpex.Adapter`
[🔗](https://github.com/naymspace/backpex/blob/0.18.3/lib/backpex/adapter.ex#L1)

Specification of the datalayer adapter.

> ### Work in progress {: .warning}
>
> The `Backpex.Adapter` behaviour is currently under heavy development and will change drastically in future updates.
> Backpex started out as `Ecto`-only and this is still deeply embedded in the core. We are working on changing this.
> Do not rely on the current API to build new adapters, as the callbacks will still change significantly. This will be
> an iterative process over the next few releases.

## Community Adapters

- **Ash**: Ash support for Backpex is maintained as a separate community project: [ash_backpex](https://github.com/enoonan/ash_backpex)

# `change`

```elixir
@callback change(
  item :: struct(),
  attrs :: map(),
  fields :: term(),
  assigns :: list(),
  live_resource :: module(),
  opts :: keyword()
) :: Ecto.Changeset.t()
```

Applies a change to a given item.

# `count`

```elixir
@callback count(
  criteria :: keyword(),
  fields :: list(),
  assigns :: map(),
  live_resource :: module()
) ::
  {:ok, non_neg_integer()}
```

Gets the total count of the current live_resource.
Possibly being constrained the item query and the search- and filter options.

# `delete_all`

```elixir
@callback delete_all(items :: [struct()], live_resource :: module()) ::
  {:ok, term()} | {:error, term()}
```

Deletes multiple items.

# `get`

```elixir
@callback get(
  primary_value :: term(),
  fields :: list(),
  assigns :: map(),
  live_resource :: module()
) ::
  {:ok, struct() | nil} | {:error, term()}
```

Gets a database record with the given primary key value.

Should return `nil` if no result was found.

# `insert`

```elixir
@callback insert(item :: struct(), live_resource :: module()) ::
  {:ok, struct()} | {:error, term()}
```

Inserts given item.

# `list`

```elixir
@callback list(
  criteria :: keyword(),
  fields :: list(),
  assigns :: map(),
  live_resource :: module()
) ::
  {:ok, list()}
```

Returns a list of items by given criteria.

# `update`

```elixir
@callback update(item :: struct(), live_resource :: module()) ::
  {:ok, struct()} | {:error, term()}
```

Updates given item.

# `update_all`

```elixir
@callback update_all(items :: [struct()], updates :: keyword(), live_resource :: module()) ::
  {:ok, non_neg_integer()}
```

Updates given items.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
