Utilities for evaluating and converting replication-related types.
Summary
Functions
Converts a type specification to a PostgreSQL cast string.
Convert a value from the eval representation to the format Postgrex expects for binary protocol encoding.
Functions
Converts a type specification to a PostgreSQL cast string.
Parameters
type- A type specification, which can be:- An atom representing a basic PostgreSQL type
- A tuple
{:array, type}for array types - A tuple
{:enum, name}for enum types
Returns
A string representation of the PostgreSQL cast type.
Examples
Basic types:
iex> Electric.Replication.Eval.type_to_pg_cast(:int4)
"int4"
iex> Electric.Replication.Eval.type_to_pg_cast(:text)
"text"
iex> Electric.Replication.Eval.type_to_pg_cast(:bool)
"bool"Array types:
iex> Electric.Replication.Eval.type_to_pg_cast({:array, :int4})
"int4[]"
iex> Electric.Replication.Eval.type_to_pg_cast({:array, :text})
"text[]"Nested array types:
iex> Electric.Replication.Eval.type_to_pg_cast({:array, {:array, :int4}})
"int4[]"Enum types:
iex> Electric.Replication.Eval.type_to_pg_cast({:enum, :my_enum})
"my_enum"
iex> Electric.Replication.Eval.type_to_pg_cast({:enum, "custom_enum"})
"custom_enum"Unsupported types raise errors:
iex> Electric.Replication.Eval.type_to_pg_cast({:row, []})
** (RuntimeError) Unsupported type: row
iex> Electric.Replication.Eval.type_to_pg_cast({:internal, :something})
** (RuntimeError) Unsupported type: internal
Convert a value from the eval representation to the format Postgrex expects for binary protocol encoding.
Most types (integers, floats, booleans, dates, times, etc.) use native Elixir types that Postgrex handles directly. UUID is a notable exception: the eval system stores UUIDs as human-readable strings, but Postgrex expects 16-byte raw binaries.