View Source Plausible.Exports (Plausible v0.0.1)
Contains functions to export data for events and sessions as Zip archives.
Summary
Functions
Renders filename for the Zip archive containing the exported CSV files.
Builds Ecto queries to export data from events_v2
and sessions_v2
tables into the format of imported_*
tables for a website.
Creates a streamable Zip archive from the provided (named) Ecto queries.
Functions
Renders filename for the Zip archive containing the exported CSV files.
Examples:
iex> archive_filename("plausible.io", ~D[2021-01-01], ~D[2024-12-31])
"plausible_io_20210101_20241231.zip"
iex> archive_filename("Bücher.example", ~D[2021-01-01], ~D[2024-12-31])
"Bücher_example_20210101_20241231.zip"
@spec export_browsers_q(pos_integer()) :: Ecto.Query.t()
@spec export_devices_q(pos_integer()) :: Ecto.Query.t()
@spec export_entry_pages_q(pos_integer()) :: Ecto.Query.t()
@spec export_exit_pages_q(pos_integer()) :: Ecto.Query.t()
@spec export_locations_q(pos_integer()) :: Ecto.Query.t()
@spec export_operating_systems_q(pos_integer()) :: Ecto.Query.t()
@spec export_pages_q(pos_integer()) :: Ecto.Query.t()
@spec export_queries(pos_integer(), extname: String.t(), date_range: Date.Range.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 export_sources_q(pos_integer()) :: Ecto.Query.t()
@spec export_visitors_q(pos_integer()) :: Ecto.Query.t()
@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)