Chronicle.Multi (chronicle v0.1.2)

Copy Markdown

Audited operations for an ordinary Ecto.Multi.

Each helper adds the requested Ecto operation followed by an audit step in the same repository transaction. No wrapper struct or special transaction function is involved.

What goes in is an Ecto.Multi and what comes out is an Ecto.Multi, so everything that already works on one keeps working: inspecting the operations, appending to it, merging it, running it with the repo's own transaction/2. A wrapper type would have to re-expose all of that, would drift from Ecto.Multi as it gained features, and would buy nothing — the audit step is just another named operation, which is what Ecto.Multi is already for.

Summary

Functions

audit(multi, name, builder, opts \\ [])

@spec audit(
  Ecto.Multi.t(),
  Ecto.Multi.name(),
  (map() -> Chronicle.Event.t()),
  keyword()
) ::
  Ecto.Multi.t()

Adds one audit step. Audit failures abort the surrounding transaction.

delete(multi, name, changeset_or_struct, opts \\ [])

insert(multi, name, changeset, opts \\ [])

record(multi, name, builder, opts \\ [])

@spec record(
  Ecto.Multi.t(),
  Ecto.Multi.name(),
  (map() -> Chronicle.Event.t() | String.t() | tuple()),
  keyword()
) :: Ecto.Multi.t()

Adds an arbitrary audit fact built from preceding Multi results.

The builder may return an Chronicle.Event, an event type, {type, data}, or {type, data, options}.

update(multi, name, changeset, opts \\ [])