View Source Plausible.Exports (Plausible v0.0.1)
Contains functions to export data for events and sessions as Zip archives.
Summary
Functions
Renders export archive filename.
Safely renders content disposition for an arbitrary export filename.
Returns the date range for the site's events data in site's timezone or nil
if there is no data
Deletes local export for a site
Deletes S3 export for a site
Builds Ecto queries to export data from events_v2
and sessions_v2
tables into the format of imported_*
tables for a website.
Gets last CSV export job for a site
Gets local export for a site
Gets S3 export for a site
Subscribes to CSV export job notifications
Schedules CSV export job to local storage
Schedules CSV export job to S3 storage
Creates a streamable Zip archive from the provided (named) Ecto queries.
Types
@type export() :: %{ path: Path.t(), name: String.t(), expires_at: DateTime.t() | nil, size: pos_integer() }
Functions
Renders export archive filename.
Examples:
iex> archive_filename("plausible.io", _created_on = ~D[2024-12-31])
"plausible_io_20241231.zip"
Safely renders content disposition for an arbitrary export filename.
Examples:
iex> content_disposition("plausible_io_20241231.zip")
"attachment; filename=\"plausible_io_20241231.zip\""
iex> content_disposition("📊.zip")
"attachment; filename=\"plausible-export.zip\"; filename*=utf-8''%F0%9F%93%8A.zip"
@spec date_range(non_neg_integer(), String.t()) :: Date.Range.t() | nil
Returns the date range for the site's events data in site's timezone or nil
if there is no data
@spec delete_local_export(pos_integer()) :: :ok
Deletes local export for a site
@spec delete_s3_export(pos_integer()) :: :ok
Deletes S3 export for a site
@spec export_queries(pos_integer(), extname: String.t(), date_range: Date.Range.t(), timezone: String.t() ) :: %{required(String.t()) => Ecto.Query.t()}
Builds Ecto queries to export data from events_v2
and sessions_v2
tables into the format of imported_*
tables for a website.
@spec get_last_export_job(pos_integer()) :: Oban.Job.t() | nil
Gets last CSV export job for a site
@spec get_local_export(pos_integer(), String.t(), String.t()) :: export() | nil
Gets local export for a site
@spec get_s3_export(pos_integer()) :: export() | nil
Gets S3 export for a site
Subscribes to CSV export job notifications
@spec schedule_local_export(pos_integer(), String.t()) :: {:ok, Oban.Job.t()} | {:error, :no_data}
Schedules CSV export job to local storage
@spec schedule_s3_export(pos_integer(), String.t()) :: {:ok, Oban.Job.t()} | {:error, :no_data}
Schedules CSV export job to S3 storage
@spec stream_archive(DBConnection.t(), %{required(String.t()) => Ecto.Query.t()}, [ Ch.query_option() ]) :: Enumerable.t()
Creates a streamable Zip archive from the provided (named) Ecto queries.
Example usage:
{:ok, pool} = Ch.start_link(pool_size: 1)
DBConnection.run(pool, fn conn ->
conn
|> stream_archive(export_queries(_site_id = 1), format: "CSVWithNames")
|> Stream.into(File.stream!("export.zip"))
|> Stream.run()
end)