Selecto.Output.Formats
(Selecto v0.4.5)
Copy Markdown
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.
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.
Types
Functions
Get available format types and their descriptions.
Returns a list of available formats with their capabilities and options.
Get performance characteristics for a given format.
Returns information about memory usage, processing time, and scalability.
@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
result- The query result tuple{rows, columns, aliases}format- The output format specificationoptions- Additional options for the transformation
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
# 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})
Validate format specification and options.
Returns :ok if the format is valid, {:error, reason} otherwise.