# `Trogon.Commanded.QueryHandler`
[🔗](https://github.com/straw-hat-team/beam-monorepo/blob/trogon_commanded@v1.0.1/apps/trogon_commanded/lib/trogon/commanded/query_handler.ex#L1)

Defines a module as a "Query Handler". For more information about queries, please read the following:

- [CQRS pattern](https://docs.microsoft.com/en-us/azure/architecture/patterns/cqrs)

# `error`

```elixir
@type error() :: any()
```

# `view_model`

```elixir
@type view_model() :: any()
```

# `handle`

```elixir
@callback handle(params :: any()) :: {:ok, view_model()} | {:error, error()}
```

Handle the incoming `params` and return the result data.

# `__using__`
*macro* 

```elixir
@spec __using__(opts :: []) :: any()
```

Convert the module into a `Trogon.Commanded.QueryHandler`.

## Usage

    defmodule MyQueryHandler do
      use Trogon.Commanded.QueryHandler
      import Ecto.Query, only: [from: 2]

      @impl Trogon.Commanded.QueryHandler
      def handle(params) do
        query = from u in User,
                  where: u.age > 18 or is_nil(params.email),
                  select: u

        {:ok, Repo.all(query)}
      end
    end

---

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