View Source ExTeal.Resource.Export behaviour (ExTeal v0.27.0)

Adds functionality for exporting a stream of records as a csv file.

Summary

Callbacks

The fields to export from the resource

Define an override to the default parser, as defined in the ex_teal config

Modify the query for a csv result

Parse a row into a CSV Encodeable list of fields

Functions

Returns a list of all fields on the schema for export

Returns the query with a select that parses all the fields into a map instead of the struct

Turns a record represented as a map and a list of atoms representing the ordered fields in the CSV into a list of values in the same order as the list of fields

Build a streamed csv and chunk the results as a response.

Convert map atom keys to strings

Callbacks

@callback export_fields() :: [atom()]

The fields to export from the resource

@callback export_module() :: module()

Define an override to the default parser, as defined in the ex_teal config

Expects the parser to have a dump_to_stream/1 function that accepts a stream of rows and returns a stream of rows.

Link to this callback

handle_export_query(t, t)

View Source
@callback handle_export_query(Ecto.Query.t(), Plug.Conn.t()) :: Ecto.Query.t()

Modify the query for a csv result

Link to this callback

parse_export_row(db_record, fields)

View Source
@callback parse_export_row(db_record :: map(), fields :: [atom()]) :: [any()]

Parse a row into a CSV Encodeable list of fields

Useful for modifying database columns into serializeable strings before the row is passed to CSV.encode/2

Functions

Link to this function

default_export_fields(resource)

View Source
@spec default_export_fields(module()) :: [atom()]

Returns a list of all fields on the schema for export

Link to this function

default_export_query(query, resource)

View Source
@spec default_export_query(Ecto.Query.t(), module()) :: Ecto.Query.t()

Returns the query with a select that parses all the fields into a map instead of the struct

Link to this function

default_parse(record, fields)

View Source
@spec default_parse(map(), [atom()]) :: [any()]

Turns a record represented as a map and a list of atoms representing the ordered fields in the CSV into a list of values in the same order as the list of fields

@spec stream(module(), Plug.Conn.t()) :: Plug.Conn.t()

Build a streamed csv and chunk the results as a response.

Uses the resource's querying functionality (filtering, searching, sorting) to return only the resources the user has selected.

Convert map atom keys to strings