View Source ExTeal.Resource.Export behaviour (ExTeal v0.28.1)
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.
@callback handle_export_query(Ecto.Query.t(), Plug.Conn.t()) :: Ecto.Query.t()
Modify the query for a csv result
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
Returns a list of all fields on the schema for export
@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
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