Bylaw.Ecto.Query.Check behaviour (bylaw_ecto_query v0.1.0-alpha.1)

Copy Markdown View Source

Behaviour for checks that validate an Ecto.Query before it runs.

Every built-in check implements this callback contract. End users should usually call Bylaw.Ecto.Query.validate/3 with an explicit check list instead of calling check modules directly.

Summary

Types

The Ecto query operation being prepared.

Check-specific options passed to the check.

The query being validated before the repo runs it.

The result returned by a query check.

Callbacks

Validates a prepared Ecto query for one check.

Types

operation()

@type operation() :: :all | :update_all | :delete_all | :stream | :insert_all

The Ecto query operation being prepared.

Ecto calls Ecto.Repo.prepare_query/3 with these operations. Query helpers such as Repo.one/2, Repo.get/3, and Repo.exists?/2 are prepared as :all.

opts()

@type opts() :: [{atom(), term()}]

Check-specific options passed to the check.

query()

@type query() :: Ecto.Query.t()

The query being validated before the repo runs it.

result()

@type result() :: :ok | {:error, [Bylaw.Ecto.Query.Issue.t(), ...]}

The result returned by a query check.

:ok means the query passed the check. {:error, issues} reports one or more query issues.

Callbacks

validate(operation, query, opts)

@callback validate(operation(), query(), opts()) :: result()

Validates a prepared Ecto query for one check.