Selecto.Output.TypeCoercion (Selecto v0.3.8)

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.

Link to this section 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.

Link to this section Functions

Link to this function

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.

Link to this function

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

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

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
Link to this function

get_elixir_type(postgres_type)

Get the Elixir type for a given PostgreSQL column type.

Link to this function

supported_types()

Get all supported PostgreSQL type mappings.