# `PgRest.Resource`
[🔗](https://github.com/agoodway/pgrest/blob/v0.1.0/lib/pg_rest/resource.ex#L1)

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

# `context`

```elixir
@type context() :: map()
```

A map of contextual information (repo, user, tenant, etc.) passed to callbacks.

# `after_load`

```elixir
@callback after_load(Ecto.Schema.t(), context()) :: Ecto.Schema.t()
```

Post-processes a record after loading from the database.

# `changeset`

```elixir
@callback changeset(Ecto.Schema.t(), map(), context()) :: Ecto.Changeset.t()
```

Builds a changeset for create and update operations.

# `handle_param`

```elixir
@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.

# `scope`

```elixir
@callback scope(Ecto.Query.t(), context()) :: Ecto.Query.t()
```

Applies scoping to the base query (e.g. tenant isolation).

# `__using__`
*macro* 

Injects PgRest resource behaviour, configuration, and default callback implementations.

---

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