OnePiece.Commanded.QueryHandler behaviour (OnePiece.Commanded v0.2.0) View Source
Link to this section Summary
Callbacks
Handle the incoming params
and return the result data.
Functions
Convert the module into a OnePiece.Commanded.QueryHandler
.
Link to this section Types
Link to this section Callbacks
Specs
Handle the incoming params
and return the result data.
Link to this section Functions
Specs
__using__(opts :: []) :: any()
Convert the module into a OnePiece.Commanded.QueryHandler
.
Usage
defmodule MyQueryHandler do
use OnePiece.Commanded.QueryHandler
import Ecto.Query, only: [from: 2]
@impl OnePiece.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