Selecto.Output.TypeCoercion (Selecto v0.4.5)

Copy Markdown

Database type coercion system for transforming raw database values to appropriate Elixir types based on PostgreSQL column types.

This module provides configurable type coercion strategies and can be extended to support custom type mappings and coercion functions.

Summary

Functions

Batch coerce a list of values with their corresponding column types.

Coerce a database value to its appropriate Elixir type.

Get the Elixir type for a given PostgreSQL column type.

Get all supported PostgreSQL type mappings.

Functions

batch_coerce(values, column_types, strategy \\ :safe, custom_coercions \\ %{})

Batch coerce a list of values with their corresponding column types.

This is more efficient than coercing values one by one when you have column type information for all values.

coerce_value(value, column_type \\ nil, strategy \\ :safe, custom_coercions \\ %{})

@spec coerce_value(term(), String.t() | nil, atom(), map()) :: term()

Coerce a database value to its appropriate Elixir type.

Parameters

  • value - The raw database value
  • column_type - The PostgreSQL column type (optional)
  • strategy - Coercion strategy (:strict, :safe, :ignore, :custom)
  • custom_coercions - Map of custom coercion functions

Coercion Strategies

  • :strict - Raise on coercion errors
  • :safe - Return original value on coercion errors
  • :ignore - Skip coercion, return raw values
  • :custom - Use custom coercion functions

get_elixir_type(postgres_type)

Get the Elixir type for a given PostgreSQL column type.

supported_types()

Get all supported PostgreSQL type mappings.