Selecto.Output.Formats (Selecto v0.3.8)

Format registry and configuration system for Selecto output formats.

This module manages the registration and configuration of different output formats and provides the main interface for transforming query results from the default {rows, columns, aliases} format to other formats like maps, structs, JSON, CSV, etc.

Link to this section Summary

Functions

Get available format types and their descriptions.

Get performance characteristics for a given format.

Transform query results from the default format to the specified output format.

Validate format specification and options.

Link to this section Types

Link to this type

format_spec()

@type format_spec() ::
  :raw
  | :maps
  | :json
  | :csv
  | {:maps, keyword()}
  | {:structs, module()}
  | {:json, keyword()}
  | {:csv, keyword()}
  | {:stream, format_spec()}
  | {:typed_maps, keyword()}

Link to this section Functions

Link to this function

available_formats()

Get available format types and their descriptions.

Returns a list of available formats with their capabilities and options.

Link to this function

performance_info(format)

Get performance characteristics for a given format.

Returns information about memory usage, processing time, and scalability.

Link to this function

transform(result, format, options \\ [])

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

Transform query results from the default format to the specified output format.

parameters

Parameters

  • result - The query result tuple {rows, columns, aliases}
  • format - The output format specification
  • options - Additional options for the transformation

format-specifications

Format Specifications

  • :raw - Return the original {rows, columns, aliases} format (no transformation)
  • :maps - Transform to list of maps with string keys
  • {:maps, options} - Transform to maps with additional options
  • {:structs, struct_module} - Transform to list of structs
  • :json - Transform to JSON string
  • {:json, options} - Transform to JSON with options
  • :csv - Transform to CSV string
  • {:csv, options} - Transform to CSV with options
  • {:stream, format} - Transform to stream (for large datasets)

examples

Examples

# Original format (no transformation)
{:ok, {rows, columns, aliases}} = transform(result, :raw)

# Maps with string keys
{:ok, maps} = transform(result, :maps)

# Maps with atom keys
{:ok, maps} = transform(result, {:maps, keys: :atoms})

# Custom struct
{:ok, structs} = transform(result, {:structs, Customer})

# JSON string
{:ok, json_string} = transform(result, :json)

# CSV with headers
{:ok, csv_string} = transform(result, {:csv, headers: true})
Link to this function

validate_format(format, options \\ [])

Validate format specification and options.

Returns :ok if the format is valid, {:error, reason} otherwise.