SysTime.Query (SysTime v0.1.0)

Copy Markdown View Source

Explicit temporal queries which do not require a Repo.travel/3 block.

Snapshot queries load the generated association-free History schema so a past value cannot accidentally preload current associations.

Entity-specific helpers require a single-column primary key. changed/3 and transparent travel support composite keys because they do not construct an identity predicate.

Summary

Functions

Returns the query for the version in effect at instant.

Returns every version with a period boundary inside [from, to).

Computes field-level changes between consecutive versions.

Compares the entity snapshots at two instants.

Compares the entity snapshots at two instants with options.

Returns prior versions of one entity, oldest first.

Returns every version of one entity, oldest first.

Functions

at(schema, id, instant)

@spec at(module(), term(), DateTime.t()) :: Ecto.Query.t()

Returns the query for the version in effect at instant.

Pass the result to Repo.one/2.

changed(schema, from, to)

@spec changed(module(), DateTime.t(), DateTime.t()) :: Ecto.Query.t()

Returns every version with a period boundary inside [from, to).

Results use the association-free history schema and are ordered by their first boundary in the window.

diff(repo, schema, id, opts \\ [])

@spec diff(Ecto.Repo.t(), module(), term(), keyword()) :: [
  %{
    at: DateTime.t(),
    changes: %{required(atom()) => %{from: term(), to: term()}}
  }
]

Computes field-level changes between consecutive versions.

:ignore defaults to [:sys_period, :inserted_at, :updated_at].

diff(repo, schema, id, from, to)

@spec diff(Ecto.Repo.t(), module(), term(), DateTime.t(), DateTime.t()) :: %{
  required(atom()) => %{from: term(), to: term()}
}

Compares the entity snapshots at two instants.

Returns one map of changed fields. Raises if the entity does not exist at either instant. Accepts the same :ignore option as diff/4.

diff(repo, schema, id, from, to, opts)

@spec diff(
  Ecto.Repo.t(),
  module(),
  term(),
  DateTime.t(),
  DateTime.t(),
  keyword()
) :: %{required(atom()) => %{from: term(), to: term()}}

Compares the entity snapshots at two instants with options.

:ignore defaults to [:sys_period, :inserted_at, :updated_at].

history(schema, id)

@spec history(module(), term()) :: Ecto.Query.t()

Returns prior versions of one entity, oldest first.

versions(schema, id)

@spec versions(module(), term()) :: Ecto.Query.t()

Returns every version of one entity, oldest first.