# `Chronicle.ReadModels`
[🔗](https://github.com/Cratis/Chronicle.Elixir/blob/main/lib/chronicle/read_models.ex#L4)

Queries Chronicle read model instances.

Read models are populated by reducers and projections. Use `get/3` to fetch
the current state of a single read model instance by its key, or `all/2` to
retrieve all instances.

## Usage

    {:ok, account} = Chronicle.ReadModels.get(MyApp.ReadModels.Account, "account-1")
    {:ok, accounts} = Chronicle.ReadModels.all(MyApp.ReadModels.Account)

With explicit client:

    {:ok, account} = Chronicle.ReadModels.get(
      MyApp.ReadModels.Account,
      "account-1",
      client: :bank_chronicle
    )

# `all`

```elixir
@spec all(
  module(),
  keyword()
) :: {:ok, [struct()]} | {:error, term()}
```

Returns all instances of the given read model.

## Options

  * `:client` — the client name (default: `Chronicle.Client`)
  * `:namespace` — overrides the client's default namespace
  * `:event_sequence_id` — the event sequence to project from (default: `"event-log"`)

# `get`

```elixir
@spec get(module(), String.t(), keyword()) :: {:ok, struct() | nil} | {:error, term()}
```

Fetches a read model instance by its key.

## Options

  * `:client` — the client name (default: `Chronicle.Client`)
  * `:namespace` — overrides the client's default namespace
  * `:event_sequence_id` — the event sequence to project from (default: `"event-log"`)

Returns `{:ok, model_struct}` on success, or `{:ok, nil}` if not found.

---

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