# `Electric.Replication.Eval`
[🔗](https://github.com/electric-sql/electric/tree/%40core/sync-service%401.6.2/packages/sync-service/lib/electric/replication/eval.ex#L1)

Utilities for evaluating and converting replication-related types.

# `type_to_pg_cast`

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

# `value_to_postgrex`

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.

---

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