Decree.Store.AppendCondition (decree v0.1.0)

Copy Markdown View Source

The :condition of a conditional Decree.Store.append_to_stream/4.

A condition is a keyword list:

  • items - a Decree.Store.Query list of items.
  • after - a position in $all, the after of a complete Decree.Store.read_query/2. The append fails if any event past it matches items. Mandatory: an absent after must never become a plain append.
  • target - optional, any term. It names what the condition protects, for a store that declares it in conditional_appends, and is compared and nothing else. A condition with one is declared by that target alone, and one with none by its streams' prefixes, so a declared prefix does not let an undeclared target in.

See "Conditional appends" in Decree.Store. A store that declares deletable refuses a condition naming it with {:error, :query_names_deletable}, as it refuses a read: see "Deletable streams" there.

Summary

Functions

Compiles a condition.

Types

t()

@type t() :: %Decree.Store.AppendCondition{
  after: non_neg_integer(),
  query: Decree.Store.Query.t(),
  target: term()
}

Functions

compile(condition)

@spec compile(condition :: term()) ::
  {:ok, t()}
  | {:error, :invalid_condition}
  | {:error, :invalid_query}
  | {:error, :tag_too_long}

Compiles a condition.

Answers {:error, :invalid_condition} for anything but a keyword list of exactly the keys above with a usable after, and passes on {:error, :invalid_query} and {:error, :tag_too_long} from Decree.Store.Query.compile/1. A refusal sends nothing to the database, so a caller's transaction stays alive.