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

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

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

Link to this section Callbacks

Specs

export_fields() :: [atom()]

The fields to export from the resource

Specs

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

Specs

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

Specs

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

Link to this section Functions

Link to this function

default_export_fields(resource)

View Source

Specs

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

Specs

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

Specs

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

Specs

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