Selecto.Output.Transformers.Maps (Selecto v0.3.12)

Transforms query results to list of maps format.

Supports various key types (strings, atoms, existing atoms) and key transformations (camelCase, snake_case). Also supports type coercion from database types to Elixir types.

Link to this section Summary

Functions

Stream transformation for large datasets.

Transform rows, columns, and aliases to list of maps.

Transform rows with type coercion based on database column types.

Link to this section Functions

Link to this function

stream_transform(rows_stream, columns, aliases, options \\ [])

Stream transformation for large datasets.

Returns a stream that transforms rows in batches to avoid loading all data into memory at once.

Link to this function

transform(rows, columns, aliases, options \\ [])

@spec transform(list(), list(), map(), keyword()) :: {:ok, [map()]} | {:error, term()}

Transform rows, columns, and aliases to list of maps.

parameters

Parameters

  • rows - List of row data (list of lists)
  • columns - List of column names
  • aliases - Map of column aliases
  • options - Transformation options

options

Options

  • :keys - Key type (:strings, :atoms, :existing_atoms). Default: :strings
  • :transform - Key name transformation (:none, :camelCase, :snake_case). Default: :none
  • :coerce_types - Whether to coerce database types to Elixir types. Default: false
  • :null_handling - How to handle NULL values (:preserve, :remove). Default: :preserve

examples

Examples

# String keys (default)
{:ok, maps} = transform(rows, columns, aliases, [])
# => [%{"name" => "John", "age" => 25}, ...]

# Atom keys
{:ok, maps} = transform(rows, columns, aliases, keys: :atoms)
# => [%{name: "John", age: 25}, ...]

# CamelCase transformation
{:ok, maps} = transform(rows, columns, aliases, keys: :atoms, transform: :camelCase)
# => [%{firstName: "John", userAge: 25}, ...]
Link to this function

transform_with_types(rows, columns, aliases, options \\ [])

@spec transform_with_types(list(), list(), map(), keyword()) ::
  {:ok, [map()]} | {:error, term()}

Transform rows with type coercion based on database column types.

This is a more advanced version that can coerce database types to proper Elixir types based on PostgreSQL column type information.