# `PgRest.Planner.Columns`
[🔗](https://github.com/agoodway/pgrest/blob/v0.2.0/lib/pg_rest/planner/columns.ex#L1)

Per-resource column data for the planner and request-column validation.

`info/2` combines the resource's config with the catalog types, keyed by Ecto field
name (the catalog itself is keyed by database column). The result is memoized next to
the catalog cache, so a request recomputes nothing. Request column names are database
names; `translate_field/3` maps them to field names, which is how scoped sources
expose their columns, and fails with PostgREST's `42703` (with Postgres's closest-column
hint) or `42501` for a column outside `readable:`.

# `info`

```elixir
@type info() :: %{
  optional(:role) =&gt; :anon | :authenticated,
  config: map(),
  table: String.t(),
  columns: [{String.t(), String.t()}],
  by_source: %{required(String.t()) =&gt; String.t()},
  types: %{required(String.t()) =&gt; String.t()},
  categories: %{required(String.t()) =&gt; String.t()}
}
```

# `exposed_name`

```elixir
@spec exposed_name(module(), String.t()) :: String.t()
```

The exposed (Ecto field) name of a database column of `module`, without the catalog.

# `info`

```elixir
@spec info(module(), module(), String.t()) :: info()
```

The info map of `module`: `columns` are `{source, field_name}` in field order,
`by_source` maps a database column to its field name, `types` and `categories` are keyed
by field name. `schema` is the resource's effective schema
(`PgRest.SQL.ScopedSource.effective_schema/2`). Calls the catalog (cached per schema) on
first use; not inside a transaction.

# `readable?`

```elixir
@spec readable?(info(), String.t()) :: boolean()
```

Whether the Ecto field is readable.

# `translate_field`

```elixir
@spec translate_field(PgRest.AST.Field.t(), info(), String.t()) ::
  {:ok, PgRest.AST.Field.t()} | {:error, PgRest.Error.t()}
```

Request column (database name) to Ecto field name, or `42703` / `42501` (401 or 403 by the
info's `:role`, which `PgRest.Planner` sets).

---

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