Lotus.Export (Lotus v0.16.4)

Copy Markdown View Source

Export functionality for Lotus.Result to various formats.

Summary

Functions

Exports a dashboard to a ZIP archive containing CSV files for each query card.

Stream a CSV export for a Query by fetching pages of results.

Converts a Result struct to CSV format using NimbleCSV. Returns iodata for efficient streaming.

Runs a Query and converts the full, unpaginated result to CSV iodata.

Converts a Result struct to JSON format. Returns a binary string containing a JSON array of objects.

Converts a Result struct to JSONL (JSON Lines) format. Returns a binary string with one JSON object per line.

Functions

export_dashboard(dashboard, opts \\ [])

@spec export_dashboard(
  Lotus.Storage.Dashboard.t(),
  keyword()
) :: {:ok, binary()} | {:error, term()}

Exports a dashboard to a ZIP archive containing CSV files for each query card.

Each query card's results are exported as a separate CSV file named after the card (using title if set, otherwise "card_{id}.csv").

Options

  • :filter_values - Map of filter names to their current values
  • Any Lotus.run_query/2 option such as :repo, :vars, :search_path

Returns {:ok, binary} where binary is the ZIP file content, or {:error, reason} on failure.

Examples

{:ok, zip_binary} = Lotus.Export.export_dashboard(dashboard)
File.write!("dashboard_export.zip", zip_binary)

{:ok, zip_binary} = Lotus.Export.export_dashboard(dashboard,
  filter_values: %{"date_range" => "2024-01-01,2024-12-31"}
)

stream_csv(q, opts \\ [])

@spec stream_csv(
  Lotus.Storage.Query.t(),
  keyword()
) :: Enumerable.t()

Stream a CSV export for a Query by fetching pages of results.

Uses windowed pagination under the hood and outputs CSV iodata chunks. The first yielded chunk contains the header row. Subsequent chunks contain rows.

Options:

  • :page_size — page size used for windowed fetching (defaults to configured Lotus default page size or 1000)
  • Any Lotus.run_query/2 option such as :repo, :vars, :search_path.

Raises on execution errors during streaming.

to_csv(result)

@spec to_csv(Lotus.Result.t()) :: [binary() | iodata()]

Converts a Result struct to CSV format using NimbleCSV. Returns iodata for efficient streaming.

to_csv(q, opts \\ [])

@spec to_csv(
  Lotus.Storage.Query.t(),
  keyword()
) :: [binary() | iodata()]

Runs a Query and converts the full, unpaginated result to CSV iodata.

Accepts a %Lotus.Storage.Query{} and Lotus options such as :repo, :vars, and :search_path. Pagination is explicitly disabled (no window) to fetch all matching rows.

Raises on execution errors.

to_json(result)

@spec to_json(Lotus.Result.t()) :: binary()

Converts a Result struct to JSON format. Returns a binary string containing a JSON array of objects.

to_jsonl(result)

@spec to_jsonl(Lotus.Result.t()) :: binary()

Converts a Result struct to JSONL (JSON Lines) format. Returns a binary string with one JSON object per line.