khepri_condition (khepri v0.6.0)

Condition support.

Conditions can be used in path patterns and keep_while conditions. They allow to point to a specific node only if conditions are met, or to match several tree nodes with a single path pattern.

A condition is an Erlang record defining a specific property. Some of them have arguments to further define the condition.

Path components (atoms and binaries) also act as conditions which check equality with the path of the tested node. This can be useful for conditions which compose other conditions: if_not(), if_all() and if_any().

Example:

  %% Matches `[stock, wood, <<"birch">>]' but not `[stock, wood, <<"oak">>]'
  [stock, wood, #if_not{condition = <<"oak">>}]
All supported conditions are described in the Data Types section.

Link to this section Summary

Types

Comparison operator in some condition().
All supported conditions.

An association between a path and a condition. As long as the condition evaluates to true, the tree node is kept. Once the condition evaluates to false, the tree node is deleted.

An association between a native path and a condition.

Return value of re:compile/1.

Link to this section Types

Link to this type

comparison_op/1

-type comparison_op(Type) :: {eq, Type} | {ne, Type} | {lt, Type} | {le, Type} | {gt, Type} | {ge, Type}.
Comparison operator in some condition().
All supported conditions.
Link to this type

keep_while/0

-type keep_while() :: #{khepri_path:path() => condition()}.

An association between a path and a condition. As long as the condition evaluates to true, the tree node is kept. Once the condition evaluates to false, the tree node is deleted.

If the keep_while conditions are false at the time of the insert, the insert fails. The only exception to that is if the keep_while condition is on the inserted node itself.

Paths in the map can be native paths or Unix-like paths. However, having two entries that resolve to the same node (one native path entry and one Unix-like path entry for instance) is undefined behavior: one of them will overwrite the other.

Example:
  khepri:put(
    StoreId,
    [foo],
    Payload,
    #{keep_while => #{
      %% The node `[foo]' will be removed as soon as `[bar]' is removed
      %% because the condition associated with `[bar]' will not be true
      %% anymore.
      [bar] => #if_node_exists{exists = true}
    }}
  ).
Link to this type

native_keep_while/0

-type native_keep_while() :: #{khepri_path:native_path() => condition()}.

An association between a native path and a condition.

This is the same as keep_while() but the paths in the map keys were converted to native paths if necessary.
Link to this type

re_compile_ret/0

-type re_compile_ret() ::
    {ok, {re_pattern, term(), term(), term(), term()}} | {error, {string(), non_neg_integer()}}.

Return value of re:compile/1.

The opaque compiled regex type, re:mp(), is unfortunately not exported by re, neither is the error tuple (at least up to Erlang/OTP 25.1).

Link to this section Functions

Link to this function

ensure_native_keep_while(KeepWhile)

-spec ensure_native_keep_while(KeepWhile) -> NativeKeepWhile
                            when KeepWhile :: keep_while(), NativeKeepWhile :: native_keep_while().