View Source Plausible.Imported.CSVImporter (Plausible v0.0.1)

CSV importer from S3 that uses ClickHouse s3 table function.

Summary

Functions

Extracts min/max date range from a list of uploads.

Extracts table name and min/max dates from the filename.

Functions

@spec date_range([String.t() | %{required(String.t()) => String.t()}, ...]) ::
  Date.Range.t()

Extracts min/max date range from a list of uploads.

Examples:

iex> date_range([
...>   %{"filename" => "imported_devices_20190101_20210101.csv"},
...>   "imported_pages_20200101_20220101.csv"
...> ])
Date.range(~D[2019-01-01], ~D[2022-01-01])

iex> date_range([])
** (ArgumentError) empty uploads
Link to this function

new_import(site, user, opts)

View Source
@spec new_import(Plausible.Site.t(), Plausible.Auth.User.t(), Keyword.t()) ::
  {:ok, Oban.Job.t()} | {:error, Ecto.Changeset.t()}
Link to this function

parse_filename!(filename)

View Source
@spec parse_filename!(String.t()) ::
  {table :: String.t(), start_date :: Date.t(), end_date :: Date.t()}

Extracts table name and min/max dates from the filename.

Examples:

iex> parse_filename!("my_data.csv")
** (ArgumentError) invalid filename

iex> parse_filename!("imported_devices_00010101_20250101.csv")
{"imported_devices", ~D[0001-01-01], ~D[2025-01-01]}