SysTime (SysTime v0.1.0)

Copy Markdown View Source

System-versioned temporal tables for Ecto and PostgreSQL.

See SysTime.Schema, SysTime.Repo, and SysTime.Migration for setup. Explicit temporal reads are available through SysTime.Query.

Summary

Functions

Returns the active travel instant, or nil outside travel.

Rewrites live sources to temporal views while travelling, changing names only.

Returns whether schema was defined with temporal_schema/2.

Runs fun in a read-only transaction resolving temporal schemas at instant. Returns the repository transaction result.

Runs travel/4 and returns the callback result.

Returns whether the calling process is inside travel/4.

Functions

as_of()

@spec as_of() :: DateTime.t() | nil

Returns the active travel instant, or nil outside travel.

rewrite(query)

@spec rewrite(Ecto.Query.t()) :: Ecto.Query.t()

Rewrites live sources to temporal views while travelling, changing names only.

temporal?(schema)

@spec temporal?(module()) :: boolean()

Returns whether schema was defined with temporal_schema/2.

travel(repo, instant, fun, opts \\ [])

@spec travel(Ecto.Repo.t(), DateTime.t(), (-> result), keyword()) ::
  {:ok, result} | {:error, term()}
when result: term()

Runs fun in a read-only transaction resolving temporal schemas at instant. Returns the repository transaction result.

travel!(repo, instant, fun, opts \\ [])

@spec travel!(Ecto.Repo.t(), DateTime.t(), (-> result), keyword()) :: result
when result: term()

Runs travel/4 and returns the callback result.

Raises SysTime.RollbackError if the callback explicitly rolls back the read-only transaction.

travelling?()

@spec travelling?() :: boolean()

Returns whether the calling process is inside travel/4.