EctoUnnest.Types (ecto_unnest v0.1.0)

Copy Markdown View Source

Ecto type inference from the schema and mapping to a PostgreSQL type.

The type is read from schema.__schema__(:type, field) and mapped to the PG type used in ::type[] casts. The :types option (override) takes precedence and is the only path for binary sources ("table"), which have no schema.

Summary

Functions

Returns the Ecto type for a field. For a binary source it requires an override from :types, but even then returns only a type stand-in — the real PG type comes from the override.

{:ok, "pg_type"} or {:error, :array_unsupported}.

Functions

ecto_type!(schema, field, override)

Returns the Ecto type for a field. For a binary source it requires an override from :types, but even then returns only a type stand-in — the real PG type comes from the override.

resolve_pg_type(ecto_type, override, kind \\ :array)

{:ok, "pg_type"} or {:error, :array_unsupported}.

override (from :types) takes precedence. kind decides about arrays:

  • :array (an unnest column) + array type -> {:error, :array_unsupported} (unnest would flatten a multi-dimensional array),
  • :scalar (a placeholder) + array type -> OK, e.g. "bigint[]" — it is an ordinary scalar parameter, so a constant array value lands in the column fine.