Behaviour and dispatch helpers for CSV export storage adapters.
Storage adapters persist generated CSV content and return a path that can be
saved on HawkEx.CSV.Export. The path is adapter-specific: local storage
returns a filesystem path, while S3 storage returns an s3://... URI.
HawkEx ships two adapters:
HawkEx.CSV.Storage.Local- writes to local disk (default).HawkEx.CSV.Storage.S3- writes to S3 (requiresex_aws).
Configuration
# Local disk (default)
config :hawk_ex,
csv_storage: {HawkEx.CSV.Storage.Local, path: "priv/exports"}
# S3
config :hawk_ex,
csv_storage: {HawkEx.CSV.Storage.S3,
bucket: "my-bucket",
prefix: "exports/"}Custom adapters
Implement this behaviour to support other storage backends:
defmodule MyApp.CSV.GCSStorage do
@behaviour HawkEx.CSV.Storage
@impl true
def write(filename, content, opts) do
bucket = Keyword.fetch!(opts, :bucket)
# write to GCS
{:ok, "gs://#{bucket}/#{filename}"}
end
@impl true
def read(path, opts) do
# read from GCS
{:ok, content}
end
@impl true
def delete(path, opts) do
# delete from GCS
:ok
end
endThen configure it:
config :hawk_ex,
csv_storage: {MyApp.CSV.GCSStorage, bucket: "my-bucket"}
Summary
Functions
Deletes stored CSV content using the configured adapter.
Reads CSV content using the configured adapter.
Writes CSV content using the configured adapter.
Callbacks
Deletes a stored export.
Returns :ok or {:error, reason}.
@callback read(path :: String.t(), opts :: keyword()) :: {:ok, content :: String.t()} | {:error, reason :: term()}
Reads CSV content from storage.
Returns {:ok, content} or {:error, reason}.
@callback write(filename :: String.t(), content :: String.t(), opts :: keyword()) :: {:ok, path :: String.t()} | {:error, reason :: term()}
Writes CSV content to storage.
Returns {:ok, path}, where path is the identifier used to read or delete
the export later.