Behavior for defining PgRest API resources from Ecto schemas.
Usage
defmodule MyApp.Orders do
use Ecto.Schema
use PgRest.Resource
schema "orders" do
field :reference, :string
field :status, :string
timestamps()
end
import Ecto.Query
@impl PgRest.Resource
def scope(query, %{tenant_id: tid}) do
where(query, [r], r.tenant_id == ^tid)
end
end
Summary
Callbacks
Post-processes a record after loading from the database.
Builds a changeset for create and update operations.
Handles a custom query parameter not recognized by the standard parser.
Applies scoping to the base query (e.g. tenant isolation).
Functions
Injects PgRest resource behaviour, configuration, and default callback implementations.
Types
@type context() :: map()
A map of contextual information (repo, user, tenant, etc.) passed to callbacks.
Callbacks
@callback after_load(Ecto.Schema.t(), context()) :: Ecto.Schema.t()
Post-processes a record after loading from the database.
@callback changeset(Ecto.Schema.t(), map(), context()) :: Ecto.Changeset.t()
Builds a changeset for create and update operations.
@callback handle_param(String.t(), String.t(), Ecto.Query.t(), context()) :: Ecto.Query.t()
Handles a custom query parameter not recognized by the standard parser.
@callback scope(Ecto.Query.t(), context()) :: Ecto.Query.t()
Applies scoping to the base query (e.g. tenant isolation).