Khepri database API.
This module exposes the database API to manipulate data.
The API is mainly made of the functions used to perform simple direct atomic
operations and queries on the database: get/1
, put/2
, delete/1
and so on. In addition to that, transaction/1
is the
starting point to run transaction functions. However the API to use inside
transaction functions is provided by khepri_tx
.
Functions in this module have simplified return values to cover most
frequent use cases. If you need more details about the queried or modified
tree nodes, like the ability to distinguish a non-existent tree node from a
tree node with no payload, you can use the khepri_adv
module.
This module also provides functions to start and stop a simple unclustered
Khepri store. For more advanced setup and clustering, see khepri_cluster
.
A Khepri store is one instance of Khepri running inside a Ra cluster (which could be made of a single Erlang node). It is possible to run multiple Khepri stores in parallel by creating multiple Ra clusters.
A Khepri store is started and configured with start/0
, start/1
or start/3
. To setup a cluster, see khepri_cluster
.
When a store is started, a store ID store_id()
is returned. This
store ID is then used by the rest of this module's API. The returned store
ID currently corresponds exactly to the Ra cluster name. It must be an atom
though; other types are unsupported.
get/1
, exists/1
, has_data/1
, etc.put/2
, delete/1
, etc.transaction/1
, etc.:
khepri:transaction(
fun() ->
khepri_tx:put(Path, Value)
end).
Simple operations are more efficient than transactions, but transactions are
more flexible.
async_option() = boolean() | ra_server:command_correlation() | ra_server:command_priority() | {ra_server:command_correlation(), ra_server:command_priority()}
Option to indicate if the command should be synchronous or asynchronous.
Values are:true
to perform an asynchronous command without a correlation
ID.false
to perform a synchronous command.async_ret() = khepri_adv:single_result() | khepri_adv:many_results() | khepri_tx:tx_fun_result() | khepri:error({not_leader, ra:server_id()})
The value returned from of a command function which was executed asynchronously.
When a caller includes a correlation ID (ra_server:command_correlation()
) async_option()
in their khepri:command_options()
on a command function, the caller will receive a
ra_event
message. Handling the notification with khepri:handle_async_ret/2
will return a list of pairs of correlation IDs
(ra_server:command_correlation()
) and the return values of the
commands which were applied, or {error, {not_leader, LeaderId}}
if the
commands could not be applied since they were sent to a non-leader member.
Note that when commands are successfully applied, the return values are in
the khepri_adv
formats - khepri_adv:single_result()
or
khepri_adv:many_results()
- rather than khepri:minimal_ret()
, even if the command was sent using a function from
the khepri
API such as khepri:put/4
.
khepri:handle_async_ret/2
.
child_list_length() = non_neg_integer()
Number of direct child nodes under a tree node.
child_list_version() = pos_integer()
Number of changes made to the list of child nodes of a tree node (child nodes added or removed).
The child list version starts at 1 when a tree node is created. It is increased by 1 each time a child is added or removed. Changes made to existing nodes are not reflected in this version.command_options() = #{timeout => timeout(), async => async_option(), reply_from => reply_from_option(), protect_against_dups => boolean()}
Options used in commands.
Commands are put/4
, delete/3
and read-write transaction/4
.
timeout
is passed to Ra command processing function.async
indicates the synchronous or asynchronous nature of the
command; see async_option()
.reply_from
indicates which cluster member should reply to the
command request; see reply_from_option()
.protect_against_dups
indicates if the deduplication mechanism should
be used for the command. This mechanism helps to avoid the same command to
be processed multiple times if there is a Ra cluster member stopping or a
change of leadership occurring at the same time. It is disabled by default,
except for R/W transactions.data() = any()
Data stored in a tree node's payload.
error() = error(any())
The error tuple returned by a function after a failure.
error(Type) = {error, Type}
Return value of a failed command or query.
favor_option() = consistency | low_latency
Option to indicate where to put the cursor between freshness of the returned data and low latency of queries.
Values are:low_latency
means that a local query is used. It is the fastest and
have the lowest latency. However, the returned data is whatever the local Ra
server has. It could be out-of-date if the local Ra server did not get or
applied the latest updates yet. The chance of blocking and timing out is
very small.consistency
means that a local query is used. However the query uses
the fence mechanism to ensure that the previous updates from the calling
process are applied locally before the query is evaluated. It will return
the most up-to-date piece of data the cluster agreed on. Note that it could
block and eventually time out if there is no quorum in the Ra cluster.filter_fun() = fun((khepri_path:native_path(), khepri:node_props()) -> boolean())
Function passed to khepri:filter/4
.
fold_acc() = any()
Term passed to and returned by a fold_fun/0
.
fold_fun() = fun((khepri_path:native_path(), khepri:node_props(), khepri:fold_acc()) -> khepri:fold_acc())
Function passed to khepri:fold/5
.
foreach_fun() = fun((khepri_path:native_path(), khepri:node_props()) -> any())
Function passed to khepri:foreach/4
.
many_payloads_ret() = many_payloads_ret(undefined)
The return value of query functions in the khepri
module that work
on a many nodes.
undefined
is returned if a tree node has no payload attached to it.
many_payloads_ret(Default) = khepri:ok(#{khepri_path:path() => khepri:data() | horus:horus_fun() | Default}) | khepri:error()
The return value of query functions in the khepri
module that work
on many nodes.
Default
is the value to return if a tree node has no payload attached to
it.
map_fun() = fun((khepri_path:native_path(), khepri:node_props()) -> khepri:map_fun_ret())
Function passed to khepri:map/4
.
map_fun_ret() = any()
Value returned by khepri:map_fun/0
.
minimal_ret() = ok | khepri:error()
The return value of update functions in the khepri
module.
node_props() = #{data => khepri:data(), has_data => boolean(), sproc => horus:horus_fun(), is_sproc => boolean(), payload_version => khepri:payload_version(), child_list_version => khepri:child_list_version(), child_list_length => khepri:child_list_length(), child_names => [khepri_path:node_id()]}
Structure used to return properties, payload and child nodes for a specific tree node.
The payload in data
or sproc
is only returned if the tree node carries
something. If that key is missing from the returned properties map, it means
the tree node has no payload.
khepri_adv
. The list of returned properties can be
configured using the props_to_return
option (see tree_options()
).
ok(Type) = {ok, Type}
The result of a function after a successful call, wrapped in an "ok" tuple.
payload_ret() = payload_ret(undefined)
The return value of query functions in the khepri
module that work
on a single tree node.
undefined
is returned if a tree node has no payload attached to it.
payload_ret(Default) = khepri:ok(khepri:data() | horus:horus_fun() | Default) | khepri:error()
The return value of query functions in the khepri
module that work
on a single tree node.
Default
is the value to return if a tree node has no payload attached to
it.
payload_version() = pos_integer()
Number of changes made to the payload of a tree node.
The payload version starts at 1 when a tree node is created. It is increased by 1 each time the payload is added, modified or removed.put_options() = #{keep_while => khepri_condition:keep_while()}
Options specific to updates.
keep_while
allows to define keep-while conditions on the
created/updated tree node.query_options() = #{condition => ra:query_condition(), timeout => timeout(), favor => favor_option()}
Options used in queries.
condition
indicates the condition on which the Ra server should wait
for before it executes the query.timeout
is passed to Ra query processing function.favor
indicates where to put the cursor between freshness of the
returned data and low latency of queries; see favor_option()
.favor
computes a condition
internally. Therefore if both options are
set, condition
takes precedence and favor
is ignored.
reply_from_option() = leader | local | {member, ra:server_id()}
Options to indicate which member of the cluster should reply to a command request.
Note that commands are always handled by the leader. This option only controls which member of the cluster carries out the reply.
leader
: the cluster leader will reply. This is the default value.{member, Member}
: the given cluster member will reply.local
: a member of the cluster on the same Erlang node as the caller
will perform the reply.reply_from
is {member, Member}
and the given member is not part of
the cluster or when reply_from
is local
and there is no member local to
the caller, the leader member will perform the reply. This mechanism uses
the cluster membership information to decide which member should reply: if
the given Member
or local member is a member of the cluster but is offline
or unreachable, no reply may be sent even though the leader may have
successfully handled the command.
store_id() = atom()
ID of a Khepri store.
This is the same as the Ra cluster name hosting the Khepri store.tree_options() = #{expect_specific_node => boolean(), props_to_return => [payload_version | child_list_version | child_list_length | child_names | payload | has_payload | raw_payload], include_root_props => boolean()}
Options used during tree traversal.
expect_specific_node
indicates if the path is expected to point to a
specific tree node or could match many nodes.props_to_return
indicates the list of properties to include in the
returned tree node properties map. The default is [payload,
payload_version]
. Note that payload
and has_payload
are a bit special:
the actually returned properties will be data
/sproc
and
has_data
/is_sproc
respectively. raw_payload
is for internal use
only.include_root_props
indicates if root properties and payload should be
returned as well.trigger_id() = atom()
An ID to identify a registered trigger.
unwrapped_many_payloads_ret() = unwrapped_many_payloads_ret(undefined)
unwrapped_many_payloads_ret(Default) = #{khepri_path:path() => khepri:data() | horus:horus_fun() | Default}
unwrapped_minimal_ret() = khepri:minimal_ret()
unwrapped_payload_ret() = unwrapped_payload_ret(undefined)
unwrapped_payload_ret(Default) = khepri:data() | horus:horus_fun() | Default
start/0 | Starts a store. |
start/1 | Starts a store. |
start/2 | Starts a store. |
start/3 | Starts a store. |
reset/0 | Resets the store on this Erlang node. |
reset/1 | Resets the store on this Erlang node. |
reset/2 | Resets the store on this Erlang node. |
stop/0 | Stops a store. |
stop/1 | Stops a store. |
get_store_ids/0 | Returns the list of running stores. |
is_empty/0 | Indicates if the store is empty or not. |
is_empty/1 | Indicates if the store is empty or not. |
is_empty/2 | Indicates if the store is empty or not. |
get/1 | Returns the payload of the tree node pointed to by the given path pattern. |
get/2 | Returns the payload of the tree node pointed to by the given path pattern. |
get/3 | Returns the payload of the tree node pointed to by the given path pattern. |
get_or/2 | Returns the payload of the tree node pointed to by the given path pattern, or a default value. |
get_or/3 | Returns the payload of the tree node pointed to by the given path pattern, or a default value. |
get_or/4 | Returns the payload of the tree node pointed to by the given path pattern, or a default value. |
get_many/1 | Returns payloads of all the tree nodes matching the given path pattern. |
get_many/2 | Returns payloads of all the tree nodes matching the given path pattern. |
get_many/3 | Returns payloads of all the tree nodes matching the given path pattern. |
get_many_or/2 | Returns payloads of all the tree nodes matching the given path pattern, or a default payload. |
get_many_or/3 | Returns payloads of all the tree nodes matching the given path pattern, or a default payload. |
get_many_or/4 | Returns payloads of all the tree nodes matching the given path pattern, or a default payload. |
exists/1 | Indicates if the tree node pointed to by the given path exists or not. |
exists/2 | Indicates if the tree node pointed to by the given path exists or not. |
exists/3 | Indicates if the tree node pointed to by the given path exists or not. |
has_data/1 | Indicates if the tree node pointed to by the given path has data or not. |
has_data/2 | Indicates if the tree node pointed to by the given path has data or not. |
has_data/3 | Indicates if the tree node pointed to by the given path has data or not. |
is_sproc/1 | Indicates if the tree node pointed to by the given path holds a stored procedure or not. |
is_sproc/2 | Indicates if the tree node pointed to by the given path holds a stored procedure or not. |
is_sproc/3 | Indicates if the tree node pointed to by the given path holds a stored procedure or not. |
count/1 | Counts all tree nodes matching the given path pattern. |
count/2 | Counts all tree nodes matching the given path pattern. |
count/3 | Counts all tree nodes matching the given path pattern. |
fold/3 | Calls Fun on successive tree nodes matching the given path pattern,
starting with Acc . |
fold/4 | Calls Fun on successive tree nodes matching the given path pattern,
starting with Acc . |
fold/5 | Calls Fun on successive tree nodes matching the given path pattern,
starting with Acc . |
foreach/2 | Calls Fun for each tree node matching the given path pattern. |
foreach/3 | Calls Fun for each tree node matching the given path pattern. |
foreach/4 | Calls Fun for each tree node matching the given path pattern. |
map/2 | Produces a new map by calling Fun for each tree node matching the
given path pattern. |
map/3 | Produces a new map by calling Fun for each tree node matching the
given path pattern. |
map/4 | Produces a new map by calling Fun for each tree node matching the
given path pattern. |
filter/2 | Returns a map for which predicate Pred holds true in tree nodes
matching the given path pattern. |
filter/3 | Returns a map for which predicate Pred holds true in tree nodes
matching the given path pattern. |
filter/4 | Returns a map for which predicate Pred holds true in tree nodes
matching the given path pattern. |
run_sproc/2 | Runs the stored procedure pointed to by the given path and returns the result. |
run_sproc/3 | Runs the stored procedure pointed to by the given path and returns the result. |
run_sproc/4 | Runs the stored procedure pointed to by the given path and returns the result. |
put/2 | Sets the payload of the tree node pointed to by the given path pattern. |
put/3 | Sets the payload of the tree node pointed to by the given path pattern. |
put/4 | Sets the payload of the tree node pointed to by the given path pattern. |
put_many/2 | Sets the payload of all the tree nodes matching the given path pattern. |
put_many/3 | Sets the payload of all the tree nodes matching the given path pattern. |
put_many/4 | Sets the payload of all the tree nodes matching the given path pattern. |
create/2 | Creates a tree node with the given payload. |
create/3 | Creates a tree node with the given payload. |
create/4 | Creates a tree node with the given payload. |
update/2 | Updates an existing tree node with the given payload. |
update/3 | Updates an existing tree node with the given payload. |
update/4 | Updates an existing tree node with the given payload. |
compare_and_swap/3 | Updates an existing tree node with the given payload only if its data matches the given pattern. |
compare_and_swap/4 | Updates an existing tree node with the given payload only if its data matches the given pattern. |
compare_and_swap/5 | Updates an existing tree node with the given payload only if its data matches the given pattern. |
delete/1 | Deletes the tree node pointed to by the given path pattern. |
delete/2 | Deletes the tree node pointed to by the given path pattern. |
delete/3 | Deletes the tree node pointed to by the given path pattern. |
delete_many/1 | Deletes all tree nodes matching the given path pattern. |
delete_many/2 | Deletes all tree nodes matching the given path pattern. |
delete_many/3 | Deletes all tree nodes matching the given path pattern. |
clear_payload/1 | Deletes the payload of the tree node pointed to by the given path pattern. |
clear_payload/2 | Deletes the payload of the tree node pointed to by the given path pattern. |
clear_payload/3 | Deletes the payload of the tree node pointed to by the given path pattern. |
clear_many_payloads/1 | Deletes the payload of all tree nodes matching the given path pattern. |
clear_many_payloads/2 | Deletes the payload of all tree nodes matching the given path pattern. |
clear_many_payloads/3 | Deletes the payload of all tree nodes matching the given path pattern. |
register_trigger/3 | Registers a trigger. |
register_trigger/4 | Registers a trigger. |
register_trigger/5 | Registers a trigger. |
register_projection/2 | Registers a projection. |
register_projection/3 | Registers a projection. |
register_projection/4 | Registers a projection. |
unregister_projections/1 | Removes the given projections from the store. |
unregister_projections/2 | Removes the given projections from the store. |
unregister_projections/3 | Removes the given projections from the store. |
has_projection/1 | Determines whether the store has a projection registered with the given name. |
has_projection/2 | Determines whether the store has a projection registered with the given name. |
has_projection/3 | Determines whether the store has a projection registered with the given name. |
transaction/1 | Runs a transaction and returns its result. |
transaction/2 | Runs a transaction and returns its result. |
transaction/3 | Runs a transaction and returns its result. |
transaction/4 | Runs a transaction and returns its result. |
transaction/5 | Runs a transaction and returns its result. |
fence/0 | Blocks until all updates received by the cluster leader are applied locally. |
fence/1 | Blocks until all updates received by the cluster leader are applied locally. |
fence/2 | Blocks until all updates received by the cluster leader are applied locally. |
handle_async_ret/1 | Handles the Ra event sent for asynchronous call results. |
handle_async_ret/2 | Handles the Ra event sent for asynchronous call results. |
'get!'/1 | |
'get!'/2 | |
'get!'/3 | |
'get_or!'/2 | |
'get_or!'/3 | |
'get_or!'/4 | |
'get_many!'/1 | |
'get_many!'/2 | |
'get_many!'/3 | |
'get_many_or!'/2 | |
'get_many_or!'/3 | |
'get_many_or!'/4 | |
'exists!'/1 | |
'exists!'/2 | |
'exists!'/3 | |
'has_data!'/1 | |
'has_data!'/2 | |
'has_data!'/3 | |
'is_sproc!'/1 | |
'is_sproc!'/2 | |
'is_sproc!'/3 | |
'count!'/1 | |
'count!'/2 | |
'count!'/3 | |
'put!'/2 | |
'put!'/3 | |
'put!'/4 | |
'put_many!'/2 | |
'put_many!'/3 | |
'put_many!'/4 | |
'create!'/2 | |
'create!'/3 | |
'create!'/4 | |
'update!'/2 | |
'update!'/3 | |
'update!'/4 | |
'compare_and_swap!'/3 | |
'compare_and_swap!'/4 | |
'compare_and_swap!'/5 | |
'delete!'/1 | |
'delete!'/2 | |
'delete!'/3 | |
'delete_many!'/1 | |
'delete_many!'/2 | |
'delete_many!'/3 | |
'clear_payload!'/1 | |
'clear_payload!'/2 | |
'clear_payload!'/3 | |
'clear_many_payloads!'/1 | |
'clear_many_payloads!'/2 | |
'clear_many_payloads!'/3 | |
export/2 | Exports a Khepri store using the Module callback module. |
export/3 | Exports a Khepri store using the Module callback module. |
export/4 | Exports a Khepri store using the Module callback module. |
import/2 | Imports a previously exported set of tree nodes using the Module
callback module. |
import/3 | Imports a previously exported set of tree nodes using the Module
callback module. |
info/0 | Lists the running stores on stdout. |
info/1 | Lists the content of specified store on stdout. |
info/2 | Lists the content of specified store on stdout. |
start() -> Ret
Ret = khepri:ok(StoreId) | khepri:error()
StoreId = khepri:store_id()
Starts a store.
See also: khepri_cluster:start/0.
start(RaSystemOrDataDir::RaSystem | DataDir) -> Ret
RaSystem = atom()
DataDir = file:filename_all()
Ret = khepri:ok(StoreId) | khepri:error()
StoreId = khepri:store_id()
Starts a store.
See also: khepri_cluster:start/1.
start(RaSystemOrDataDir::RaSystem | DataDir, StoreIdOrRaServerConfig::StoreId | RaServerConfig) -> Ret
RaSystem = atom()
DataDir = file:filename_all()
StoreId = store_id()
RaServerConfig = khepri_cluster:incomplete_ra_server_config()
Ret = khepri:ok(StoreId) | khepri:error()
StoreId = khepri:store_id()
Starts a store.
See also: khepri_cluster:start/2.
start(RaSystemOrDataDir::RaSystem | DataDir, StoreIdOrRaServerConfig::StoreId | RaServerConfig, Timeout) -> Ret
RaSystem = atom()
DataDir = file:filename_all()
StoreId = store_id()
RaServerConfig = khepri_cluster:incomplete_ra_server_config()
Timeout = timeout()
Ret = khepri:ok(StoreId) | khepri:error()
StoreId = khepri:store_id()
Starts a store.
See also: khepri_cluster:start/3.
reset() -> Ret
Ret = ok | error()
Resets the store on this Erlang node.
See also: khepri_cluster:reset/0.
reset(StoreIdOrTimeout::StoreId | Timeout) -> Ret
StoreId = khepri:store_id()
Timeout = timeout()
Ret = ok | khepri:error()
Resets the store on this Erlang node.
See also: khepri_cluster:reset/1.
reset(StoreId, Timeout) -> Ret
StoreId = khepri:store_id()
Timeout = timeout()
Ret = ok | error()
Resets the store on this Erlang node.
See also: khepri_cluster:reset/2.
stop() -> Ret
Ret = ok | khepri:error()
Stops a store.
See also: khepri_cluster:stop/0.
stop(StoreId) -> Ret
StoreId = khepri:store_id()
Ret = ok | khepri:error()
Stops a store.
See also: khepri_cluster:stop/1.
get_store_ids() -> [StoreId]
StoreId = store_id()
Returns the list of running stores.
See also: khepri_cluster:get_store_ids/0.
is_empty() -> IsEmpty | Error
IsEmpty = boolean()
Error = khepri:error()
Indicates if the store is empty or not.
Calling this function is the same as callingis_empty(StoreId)
with the
default store ID (see khepri_cluster:get_default_store_id/0
).
See also: is_empty/1, is_empty/2.
is_empty(StoreId) -> IsEmpty | Error
StoreId = khepri:store_id()
IsEmpty = boolean()
Error = khepri:error()
is_empty(Options) -> IsEmpty | Error
Options = khepri:query_options() | khepri:tree_options()
IsEmpty = boolean()
Error = khepri:error()
Indicates if the store is empty or not.
This function accepts the following two forms:is_empty(StoreId)
. Calling it is the same as calling
is_empty(StoreId, #{})
.is_empty(Options)
. Calling it is the same as calling
is_empty(StoreId, Options)
with the default store ID (see khepri_cluster:get_default_store_id/0
).See also: is_empty/2.
is_empty(StoreId, Options) -> IsEmpty | Error
StoreId = khepri:store_id()
Options = khepri:query_options() | khepri:tree_options()
IsEmpty = boolean()
Error = khepri:error()
StoreId
: the name of the Khepri store.
Options
: query options such as favor
.
returns: true
if the store is empty, false
if it is not, or an {error,
Reason}
tuple.
Indicates if the store is empty or not.
get(PathPattern) -> Ret
PathPattern = khepri_path:pattern()
Ret = khepri:payload_ret()
Returns the payload of the tree node pointed to by the given path pattern.
Calling this function is the same as callingget(StoreId, PathPattern)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
get(StoreId, PathPattern) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Ret = khepri:payload_ret()
get(PathPattern, Options) -> Ret
PathPattern = khepri_path:pattern()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:payload_ret()
Returns the payload of the tree node pointed to by the given path pattern.
This function accepts the following two forms:get(StoreId, PathPattern)
. Calling it is the same as calling
get(StoreId, PathPattern, #{})
.get(PathPattern, Options)
. Calling it is the same as calling
get(StoreId, PathPattern, Options)
with the default store ID (see khepri_cluster:get_default_store_id/0
).See also: get/3.
get(StoreId, PathPattern, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:payload_ret()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree node to get.
Options
: query options.
returns: an {ok, Payload | undefined}
tuple or an {error, Reason}
tuple.
Returns the payload of the tree node pointed to by the given path pattern.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
The PathPattern
must target a specific tree node. In other words,
updating many nodes with the same payload is denied. That fact is checked
before the tree node is looked up: so if a condition in the path could
potentially match several nodes, an exception is raised, even though only
one tree node would match at the time.
The returned {ok, Payload}
tuple contains the payload of the targeted
tree node, or {ok, undefined}
if the tree node had no payload.
value
%% Query the tree node at `/:foo/:bar'.
{ok, value} = khepri:get(StoreId, [foo, bar]).
Example: query an existing tree node with no payload
%% Query the tree node at `/:no_payload'.
{ok, undefined} = khepri:get(StoreId, [no_payload]).
Example: query a non-existent tree node
%% Query the tree node at `/:non_existent'.
{error, ?khepri_error(node_not_found, _)} = khepri:get(
StoreId, [non_existent]).
See also: get_many/3, get_or/3, khepri_adv:get/3.
get_or(PathPattern, Default) -> Ret
PathPattern = khepri_path:pattern()
Default = khepri:data()
Ret = khepri:payload_ret(Default)
Returns the payload of the tree node pointed to by the given path pattern, or a default value.
Calling this function is the same as callingget_or(StoreId, PathPattern,
Default)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
get_or(StoreId, PathPattern, Default) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Default = khepri:data()
Ret = khepri:payload_ret(Default)
get_or(PathPattern, Default, Options) -> Ret
PathPattern = khepri_path:pattern()
Default = khepri:data()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:payload_ret(Default)
Returns the payload of the tree node pointed to by the given path pattern, or a default value.
This function accepts the following two forms:get_or(StoreId, PathPattern, Default)
. Calling it is the same as
calling get_or(StoreId, PathPattern, Default, #{})
.get_or(PathPattern, Default, Options)
. Calling it is the same as
calling get_or(StoreId, PathPattern, Default, Options)
with the default
store ID (see khepri_cluster:get_default_store_id/0
).See also: get_or/4.
get_or(StoreId, PathPattern, Default, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Default = khepri:data()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:payload_ret(Default)
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree node to get.
Default
: the default value to return in case the tree node has no
payload or does not exist.
Options
: query options.
returns: an {ok, Payload | Default}
tuple or an {error, Reason}
tuple.
Returns the payload of the tree node pointed to by the given path pattern, or a default value.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
The PathPattern
must target a specific tree node. In other words,
updating many nodes with the same payload is denied. That fact is checked
before the tree node is looked up: so if a condition in the path could
potentially match several nodes, an exception is raised, even though only
one tree node would match at the time.
The returned {ok, Payload}
tuple contains the payload of the targeted
tree node, or {ok, Default}
if the tree node had no payload or was not
found.
value
%% Query the tree node at `/:foo/:bar'.
{ok, value} = khepri:get_or(StoreId, [foo, bar], default).
Example: query an existing tree node with no payload
%% Query the tree node at `/:no_payload'.
{ok, default} = khepri:get_or(StoreId, [no_payload], default).
Example: query a non-existent tree node
%% Query the tree node at `/:non_existent'.
{ok, default} = khepri:get_or(StoreId, [non_existent], default).
See also: get/3, get_many_or/4, khepri_adv:get/3.
get_many(PathPattern) -> Ret
PathPattern = khepri_path:pattern()
Ret = khepri:many_payloads_ret()
Returns payloads of all the tree nodes matching the given path pattern.
Calling this function is the same as callingget_many(StoreId,
PathPattern)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: get_many/2, get_many/3.
get_many(StoreId, PathPattern) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Ret = khepri:many_payloads_ret()
get_many(PathPattern, Options) -> Ret
PathPattern = khepri_path:pattern()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:many_payloads_ret()
Returns payloads of all the tree nodes matching the given path pattern.
This function accepts the following two forms:get_many(StoreId, PathPattern)
. Calling it is the same as calling
get_many(StoreId, PathPattern, #{})
.get_many(PathPattern, Options)
. Calling it is the same as calling
get_many(StoreId, PathPattern, Options)
with the default store ID (see
khepri_cluster:get_default_store_id/0
).See also: get_many/3.
get_many(StoreId, PathPattern, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:many_payloads_ret()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree nodes to get.
Options
: query options.
returns: an {ok, PayloadsMap}
tuple or an {error, Reason}
tuple.
Returns payloads of all the tree nodes matching the given path pattern.
Calling this function is the same as calling get_many_or(StoreId,
PathPattern, undefined, Options)
.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
The returned {ok, PayloadsMap}
tuple contains a map where keys correspond
to the path to a tree node matching the path pattern. Each key then points
to the payload of that matching tree node, or Default
if the tree node
had no payload.
%% Get all nodes in the tree. The tree is:
%% <root>
%% `-- foo
%% `-- bar = value
{ok, #{[foo] := undefined,
[foo, bar] := value}} = khepri:get_many(
StoreId,
[?KHEPRI_WILDCARD_STAR_STAR]).
See also: get/3, get_many_or/4, khepri_adv:get_many/3.
get_many_or(PathPattern, Default) -> Ret
PathPattern = khepri_path:pattern()
Default = khepri:data()
Ret = khepri:many_payloads_ret(Default)
Returns payloads of all the tree nodes matching the given path pattern, or a default payload.
Calling this function is the same as callingget_many_or(StoreId,
PathPattern, Default)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: get_many_or/3, get_many_or/4.
get_many_or(StoreId, PathPattern, Default) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Default = khepri:data()
Ret = khepri:many_payloads_ret(Default)
get_many_or(PathPattern, Default, Options) -> Ret
PathPattern = khepri_path:pattern()
Default = khepri:data()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:many_payloads_ret(Default)
Returns payloads of all the tree nodes matching the given path pattern, or a default payload.
This function accepts the following two forms:get_many_or(StoreId, PathPattern, Default)
. Calling it is the same as
calling get_many_or(StoreId, PathPattern, Default, #{})
.get_many_or(PathPattern, Default, Options)
. Calling it is the same as
calling get_many_or(StoreId, PathPattern, Default, Options)
with the
default store ID (see khepri_cluster:get_default_store_id/0
).See also: get_many_or/4.
get_many_or(StoreId, PathPattern, Default, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Default = khepri:data()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:many_payloads_ret(Default)
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree nodes to get.
Default
: the default value to set in PayloadsMap
for tree nodes
with no payload.
Options
: query options.
returns: an {ok, PayloadsMap}
tuple or an {error, Reason}
tuple.
Returns payloads of all the tree nodes matching the given path pattern, or a default payload.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
The returned {ok, PayloadsMap}
tuple contains a map where keys correspond
to the path to a tree node matching the path pattern. Each key then points
to the payload of that matching tree node, or Default
if the tree node
had no payload.
%% Get all nodes in the tree. The tree is:
%% <root>
%% `-- foo
%% `-- bar = value
{ok, #{[foo] := default,
[foo, bar] := value}} = khepri:get_many_or(
StoreId,
[?KHEPRI_WILDCARD_STAR_STAR],
default).
See also: get_many/3, get_or/4, khepri_adv:get_many/3.
exists(PathPattern) -> Exists | Error
PathPattern = khepri_path:pattern()
Exists = boolean()
Error = khepri:error()
Indicates if the tree node pointed to by the given path exists or not.
Calling this function is the same as callingexists(StoreId, PathPattern)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
exists(StoreId, PathPattern) -> Exists | Error
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Exists = boolean()
Error = khepri:error()
exists(PathPattern, Options) -> Exists | Error
PathPattern = khepri_path:pattern()
Options = khepri:query_options() | khepri:tree_options()
Exists = boolean()
Error = khepri:error()
Indicates if the tree node pointed to by the given path exists or not.
This function accepts the following two forms:exists(StoreId, PathPattern)
. Calling it is the same as calling
exists(StoreId, PathPattern, #{})
.exists(PathPattern, Options)
. Calling it is the same as calling
exists(StoreId, PathPattern, Options)
with the default store ID (see
khepri_cluster:get_default_store_id/0
).See also: exists/3.
exists(StoreId, PathPattern, Options) -> Exists | Error
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Options = khepri:query_options() | khepri:tree_options()
Exists = boolean()
Error = khepri:error()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the nodes to check.
Options
: query options such as favor
.
returns: true
if the tree node exists, false
if it does not, or an
{error, Reason}
tuple.
Indicates if the tree node pointed to by the given path exists or not.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
PathPattern
must target a specific tree node. In other words,
updating many nodes with the same payload is denied. That fact is checked
before the tree node is looked up: so if a condition in the path could
potentially match several nodes, an exception is raised, even though only
one tree node would match at the time.
See also: get/3.
has_data(PathPattern) -> HasData | Error
PathPattern = khepri_path:pattern()
HasData = boolean()
Error = khepri:error()
Indicates if the tree node pointed to by the given path has data or not.
Calling this function is the same as callinghas_data(StoreId,
PathPattern)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: has_data/2, has_data/3.
has_data(StoreId, PathPattern) -> HasData | Error
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
HasData = boolean()
Error = khepri:error()
has_data(PathPattern, Options) -> HasData | Error
PathPattern = khepri_path:pattern()
Options = khepri:query_options() | khepri:tree_options()
HasData = boolean()
Error = khepri:error()
Indicates if the tree node pointed to by the given path has data or not.
This function accepts the following two forms:has_data(StoreId, PathPattern)
. Calling it is the same as calling
has_data(StoreId, PathPattern, #{})
.has_data(PathPattern, Options)
. Calling it is the same as calling
has_data(StoreId, PathPattern, Options)
with the default store ID (see
khepri_cluster:get_default_store_id/0
).See also: has_data/3.
has_data(StoreId, PathPattern, Options) -> HasData | Error
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Options = khepri:query_options() | khepri:tree_options()
HasData = boolean()
Error = khepri:error()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the nodes to check.
Options
: query options such as favor
.
returns: true
if tree the node holds data, false
if it does not exist,
has no payload or holds a stored procedure, or an {error, Reason}
tuple.
Indicates if the tree node pointed to by the given path has data or not.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
PathPattern
must target a specific tree node. In other words,
updating many nodes with the same payload is denied. That fact is checked
before the tree node is looked up: so if a condition in the path could
potentially match several nodes, an exception is raised, even though only
one tree node would match at the time.
See also: get/3.
is_sproc(PathPattern) -> IsSproc | Error
PathPattern = khepri_path:pattern()
IsSproc = boolean()
Error = khepri:error()
Indicates if the tree node pointed to by the given path holds a stored procedure or not.
Calling this function is the same as callingis_sproc(StoreId,
PathPattern)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: is_sproc/2, is_sproc/3.
is_sproc(StoreId, PathPattern) -> IsSproc | Error
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
IsSproc = boolean()
Error = khepri:error()
is_sproc(PathPattern, Options) -> IsSproc | Error
PathPattern = khepri_path:pattern()
Options = khepri:query_options() | khepri:tree_options()
IsSproc = boolean()
Error = khepri:error()
Indicates if the tree node pointed to by the given path holds a stored procedure or not.
This function accepts the following two forms:is_sproc(StoreId, PathPattern)
. Calling it is the same as calling
is_sproc(StoreId, PathPattern, #{})
.is_sproc(PathPattern, Options)
. Calling it is the same as calling
is_sproc(StoreId, PathPattern, Options)
with the default store ID (see
khepri_cluster:get_default_store_id/0
).See also: is_sproc/3.
is_sproc(StoreId, PathPattern, Options) -> IsSproc | Error
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Options = khepri:query_options() | khepri:tree_options()
IsSproc = boolean()
Error = khepri:error()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the nodes to check.
Options
: query options such as favor
.
returns: true
if the tree node holds a stored procedure, false
if it
does not exist, has no payload or holds data, or an {error, Reason}
tuple.
Indicates if the tree node pointed to by the given path holds a stored procedure or not.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
PathPattern
must target a specific tree node. In other words,
updating many nodes with the same payload is denied. That fact is checked
before the tree node is looked up: so if a condition in the path could
potentially match several nodes, an exception is raised, even though only
one tree node would match at the time.
See also: get/3.
count(PathPattern) -> Ret
PathPattern = khepri_path:pattern()
Ret = ok(Count) | error()
Count = non_neg_integer()
Counts all tree nodes matching the given path pattern.
Calling this function is the same as callingcount(StoreId,
PathPattern)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
count(StoreId, PathPattern) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Ret = ok(Count) | error()
Count = non_neg_integer()
count(PathPattern, Options) -> Ret
PathPattern = khepri_path:pattern()
Options = khepri:query_options() | khepri:tree_options()
Ret = ok(Count) | error()
Count = non_neg_integer()
Counts all tree nodes matching the given path pattern.
This function accepts the following two forms:count(StoreId, PathPattern)
. Calling it is the same as calling
count(StoreId, PathPattern, #{})
.count(PathPattern, Options)
. Calling it is the same as calling
count(StoreId, PathPattern, Options)
with the default store ID (see
khepri_cluster:get_default_store_id/0
).See also: count/3.
count(StoreId, PathPattern, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Options = khepri:query_options() | khepri:tree_options()
Ret = ok(Count) | error()
Count = non_neg_integer()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the nodes to count.
Options
: query options such as favor
.
returns: an {ok, Count}
tuple with the number of matching tree nodes, or
an {error, Reason}
tuple.
Counts all tree nodes matching the given path pattern.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
The root node is not included in the count.
Example:%% Query the tree node at `/:foo/:bar'.
{ok, 3} = khepri:count(StoreId, [foo, ?KHEPRI_WILDCARD_STAR]).
fold(PathPattern, Fun, Acc) -> Ret
PathPattern = khepri_path:pattern()
Fun = khepri:fold_fun()
Acc = khepri:fold_acc()
Ret = khepri:ok(NewAcc) | khepri:error()
NewAcc = Acc
Calls Fun
on successive tree nodes matching the given path pattern,
starting with Acc
.
fold(StoreId, PathPattern,
Fun, Acc)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
fold(StoreId, PathPattern, Fun, Acc) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Fun = khepri:fold_fun()
Acc = khepri:fold_acc()
Ret = khepri:ok(NewAcc) | khepri:error()
NewAcc = Acc
fold(PathPattern, Fun, Acc, Options) -> Ret
PathPattern = khepri_path:pattern()
Fun = khepri:fold_fun()
Acc = khepri:fold_acc()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:ok(NewAcc) | khepri:error()
NewAcc = Acc
Calls Fun
on successive tree nodes matching the given path pattern,
starting with Acc
.
fold(StoreId, PathPattern, Fun, Acc)
. Calling it is the same as
calling fold(StoreId, PathPattern, Fun, Acc, #{})
.fold(PathPattern, Fun, Acc, Options)
. Calling it is the same as
calling fold(StoreId, PathPattern, Fun, Acc, Options)
with the default
store ID (see khepri_cluster:get_default_store_id/0
).See also: fold/5.
fold(StoreId, PathPattern, Fun, Acc, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Fun = khepri:fold_fun()
Acc = khepri:fold_acc()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:ok(NewAcc) | khepri:error()
NewAcc = Acc
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree nodes to get.
Fun
: the function to call for each matching tree node.
Acc
: the Erlang term to pass to the first call to Fun
.
Options
: query options.
returns: an {ok, NewAcc}
tuple or an {error, Reason}
tuple.
Calls Fun
on successive tree nodes matching the given path pattern,
starting with Acc
.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
maps:fold/3
, Fun
must accept the
following arguments:
Acc
for the first matched tree node, or
the return value of the previous call to Fun
The returned {ok, NewAcc}
tuple contains the return value of the last call
to Fun
, or Acc
if no tree nodes matched the given path pattern.
%% List all tree node paths in the tree. The tree is:
%% <root>
%% `-- foo
%% `-- bar = value
{ok, [[foo], [foo, bar]]} = khepri:fold(
StoreId,
[?KHEPRI_WILDCARD_STAR_STAR],
fun(Path, _NodeProps, Acc) ->
[Path | Acc]
end, []).
foreach(PathPattern, Fun) -> Ret
PathPattern = khepri_path:pattern()
Fun = khepri:foreach_fun()
Ret = ok | khepri:error()
Calls Fun
for each tree node matching the given path pattern.
foreach(StoreId, PathPattern,
Fun)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: foreach/3, foreach/4.
foreach(StoreId, PathPattern, Fun) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Fun = khepri:foreach_fun()
Ret = ok | khepri:error()
foreach(PathPattern, Fun, Options) -> Ret
PathPattern = khepri_path:pattern()
Fun = khepri:foreach_fun()
Options = khepri:query_options() | khepri:tree_options()
Ret = ok | khepri:error()
Calls Fun
for each tree node matching the given path pattern.
foreach(StoreId, PathPattern, Fun)
. Calling it is the same as
calling foreach(StoreId, PathPattern, Fun, #{})
.foreach(PathPattern, Fun, Options)
. Calling it is the same as
calling foreach(StoreId, PathPattern, Fun, Options)
with the default
store ID (see khepri_cluster:get_default_store_id/0
).See also: foreach/4.
foreach(StoreId, PathPattern, Fun, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Fun = khepri:foreach_fun()
Options = khepri:query_options() | khepri:tree_options()
Ret = ok | khepri:error()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree nodes to get.
Fun
: the function to call for each matching tree node.
Options
: query options.
returns: ok
or an {error, Reason}
tuple.
Calls Fun
for each tree node matching the given path pattern.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
maps:foreach/2
, Fun
must accept the
following arguments:
%% Print all tree node paths in the tree. The tree is:
%% <root>
%% `-- foo
%% `-- bar = value
ok = khepri:foreach(
StoreId,
[?KHEPRI_WILDCARD_STAR_STAR],
fun(Path, _NodeProps) ->
io:format("Path ~0p~n", [Path])
end).
map(PathPattern, Fun) -> Ret
PathPattern = khepri_path:pattern()
Fun = khepri:map_fun()
Ret = khepri:ok(Map) | khepri:error()
Map = #{khepri_path:native_path() => khepri:map_fun_ret()}
Produces a new map by calling Fun
for each tree node matching the
given path pattern.
map(StoreId, PathPattern,
Fun)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
map(StoreId, PathPattern, Fun) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Fun = khepri:map_fun()
Ret = khepri:ok(Map) | khepri:error()
Map = #{khepri_path:native_path() => khepri:map_fun_ret()}
map(PathPattern, Fun, Options) -> Ret
PathPattern = khepri_path:pattern()
Fun = khepri:map_fun()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:ok(Map) | khepri:error()
Map = #{khepri_path:native_path() => khepri:map_fun_ret()}
Produces a new map by calling Fun
for each tree node matching the
given path pattern.
map(StoreId, PathPattern, Fun)
. Calling it is the same as
calling map(StoreId, PathPattern, Fun, #{})
.map(PathPattern, Fun, Options)
. Calling it is the same as
calling map(StoreId, PathPattern, Fun, Options)
with the default
store ID (see khepri_cluster:get_default_store_id/0
).See also: map/4.
map(StoreId, PathPattern, Fun, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Fun = khepri:map_fun()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:ok(Map) | khepri:error()
Map = #{khepri_path:native_path() => khepri:map_fun_ret()}
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree nodes to get.
Fun
: the function to call for each matching tree node.
Options
: query options.
returns: {ok, Map}
or an {error, Reason}
tuple.
Produces a new map by calling Fun
for each tree node matching the
given path pattern.
The produced map uses the tree node path as the key, like get_many/3
and the return value of Fun
as the value.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
maps:map/2
, Fun
must accept the
following arguments:
%% The tree is:
%% <root>
%% `-- foo
%% `-- bar = value
{ok, #{[foo] => "/:foo",
[foo, bar] => "/:foo/:bar"}} = khepri:map(
StoreId,
[?KHEPRI_WILDCARD_STAR_STAR],
fun(Path, _NodeProps) ->
khepri_path:to_string(Path)
end).
filter(PathPattern, Pred) -> Ret
PathPattern = khepri_path:pattern()
Pred = khepri:filter_fun()
Ret = khepri:many_payloads_ret()
Returns a map for which predicate Pred
holds true in tree nodes
matching the given path pattern.
filter(StoreId, PathPattern,
Pred)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
filter(StoreId, PathPattern, Pred) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Pred = khepri:filter_fun()
Ret = khepri:many_payloads_ret()
filter(PathPattern, Pred, Options) -> Ret
PathPattern = khepri_path:pattern()
Pred = khepri:filter_fun()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:many_payloads_ret()
Returns a map for which predicate Pred
holds true in tree nodes
matching the given path pattern.
filter(StoreId, PathPattern, Pred)
. Calling it is the same as
calling filter(StoreId, PathPattern, Pred, #{})
.filter(PathPattern, Pred, Options)
. Calling it is the same as
calling filter(StoreId, PathPattern, Pred, Options)
with the default
store ID (see khepri_cluster:get_default_store_id/0
).See also: filter/4.
filter(StoreId, PathPattern, Pred, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Pred = khepri:filter_fun()
Options = khepri:query_options() | khepri:tree_options()
Ret = khepri:many_payloads_ret()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree nodes to get.
Pred
: the function to call for each matching tree node.
Options
: query options.
returns: {ok, Map}
or an {error, Reason}
tuple.
Returns a map for which predicate Pred
holds true in tree nodes
matching the given path pattern.
The produced map only contains tree nodes for which Pred
returned true.
The map has the same form as the one returned by get_many/3
otherwise.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
maps:filter/2
, Pred
must accept the
following arguments:
/:foo
%% The tree is:
%% <root>
%% `-- foo
%% `-- bar = value
{ok, #{[foo] => undefined,
[foo, bar] => value}} = khepri:filter(
StoreId,
[?KHEPRI_WILDCARD_STAR_STAR],
fun
([foo | _], _NodeProps) -> true;
(_Path, _NodeProps) -> false
end).
run_sproc(PathPattern, Args) -> Ret
PathPattern = khepri_path:pattern()
Args = list()
Ret = any()
Runs the stored procedure pointed to by the given path and returns the result.
Calling this function is the same as callingrun_sproc(StoreId,
PathPattern, Args)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: run_sproc/3, run_sproc/4.
run_sproc(StoreId, PathPattern, Args) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Args = list()
Ret = any()
run_sproc(PathPattern, Args, Options) -> Ret
PathPattern = khepri_path:pattern()
Args = list()
Options = khepri:query_options() | khepri:tree_options()
Ret = any()
Runs the stored procedure pointed to by the given path and returns the result.
This function accepts the following two forms:run_sproc(StoreId, PathPattern, Args)
. Calling it is the same as
calling run_sproc(StoreId, PathPattern, Args, #{})
.run_sproc(PathPattern, Args, Options)
. Calling it is the same as
calling run_sproc(StoreId, PathPattern, Args, Options)
with the default
store ID (see khepri_cluster:get_default_store_id/0
).See also: run_sproc/4.
run_sproc(StoreId, PathPattern, Args, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Args = list()
Options = khepri:query_options()
Ret = any()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree node holding the
stored procedure.
Args
: the list of args to pass to the stored procedure; its length
must be equal to the stored procedure arity.
Options
: query options.
returns: the result of the stored procedure execution, or throws an exception if the tree node does not exist, does not hold a stored procedure or if there was an error.
Runs the stored procedure pointed to by the given path and returns the result.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
The PathPattern
must target a specific tree node. In other words,
updating many nodes with the same payload is denied. That fact is checked
before the tree node is looked up: so if a condition in the path could
potentially match several nodes, an exception is raised, even though only
one tree node would match at the time.
Args
list must match the number of arguments expected by
the stored procedure.
See also: is_sproc/3.
put(PathPattern, Data) -> Ret
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Ret = khepri:minimal_ret()
Sets the payload of the tree node pointed to by the given path pattern.
Calling this function is the same as callingput(StoreId, PathPattern,
Data)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
put(StoreId, PathPattern, Data) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Ret = khepri:minimal_ret()
Sets the payload of the tree node pointed to by the given path pattern.
Calling this function is the same as callingput(StoreId, PathPattern,
Data, #{})
.
See also: put/4.
put(StoreId, PathPattern, Data, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Options = khepri:command_options() | khepri:tree_options() | khepri:put_options()
Ret = khepri:minimal_ret() | khepri_machine:async_ret()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree node to create or
modify.
Data
: the Erlang term or function to store, or a khepri_payload:payload()
structure.
Options
: command options.
returns: in the case of a synchronous call, ok
or an {error, Reason}
tuple; in the case of an asynchronous call, always ok
(the actual return
value may be sent by a message if a correlation ID was specified).
Sets the payload of the tree node pointed to by the given path pattern.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
The PathPattern
must target a specific tree node. In other words,
updating many nodes with the same payload is denied. That fact is checked
before the tree node is looked up: so if a condition in the path could
potentially match several nodes, an exception is raised, even though only
one tree node would match at the time.
When using a simple path (i.e. without conditions), if the targeted tree node does not exist, it is created using the given payload. If the targeted tree node exists, it is updated with the given payload and its payload version is increased by one. Missing parent nodes are created on the way.
When using a path pattern, the behavior is the same. However if a condition in the path pattern is not met, an error is returned and the tree structure is not modified.
The payload must be one of the following form:khepri_payload:no_payload()
),
using the marker returned by khepri_payload:none/0
, meaning there
will be no payload attached to the tree node and the existing payload will
be discarded if anykhepri_payload:sproc()
recordkhepri_payload:data()
recordIt is possible to wrap the payload in its internal structure explicitly
using the khepri_payload
module directly.
The Options
map may specify command-level options; see khepri:command_options()
, khepri:tree_options()
and khepri:put_options()
.
When doing an asynchronous update, the handle_async_ret/2
function can be used to handle the message received from Ra.
%% Insert a tree node at `/:foo/:bar', overwriting the previous value.
ok = khepri:put(StoreId, [foo, bar], new_value).
See also: compare_and_swap/5, create/4, put_many/4, update/4, khepri_adv:put/4.
put_many(PathPattern, Data) -> Ret
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Ret = khepri:minimal_ret()
Sets the payload of all the tree nodes matching the given path pattern.
Calling this function is the same as callingput_many(StoreId, PathPattern,
Data)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: put_many/3, put_many/4.
put_many(StoreId, PathPattern, Data) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Ret = khepri:minimal_ret()
Sets the payload of all the tree nodes matching the given path pattern.
Calling this function is the same as callingput_many(StoreId, PathPattern,
Data, #{})
.
See also: put_many/4.
put_many(StoreId, PathPattern, Data, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Options = khepri:command_options() | khepri:tree_options() | khepri:put_options()
Ret = khepri:minimal_ret() | khepri_machine:async_ret()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree node to create or
modify.
Data
: the Erlang term or function to store, or a khepri_payload:payload()
structure.
Options
: command options.
returns: in the case of a synchronous call, ok
or an {error, Reason}
tuple; in the case of an asynchronous call, always ok
(the actual return
value may be sent by a message if a correlation ID was specified).
Sets the payload of all the tree nodes matching the given path pattern.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
When using a simple path (i.e. without conditions), if the targeted tree node does not exist, it is created using the given payload. If the targeted tree node exists, it is updated with the given payload and its payload version is increased by one. Missing parent nodes are created on the way.
When using a path pattern, the behavior is the same. However if a condition in the path pattern is not met, an error is returned and the tree structure is not modified.
The payload must be one of the following form:khepri_payload:no_payload()
),
using the marker returned by khepri_payload:none/0
, meaning there
will be no payload attached to the tree node and the existing payload will
be discarded if anykhepri_payload:sproc()
recordkhepri_payload:data()
recordIt is possible to wrap the payload in its internal structure explicitly
using the khepri_payload
module directly.
The Options
map may specify command-level options; see khepri:command_options()
, khepri:tree_options()
and khepri:put_options()
.
When doing an asynchronous update, the handle_async_ret/2
function can be used to handle the message received from Ra.
%% Insert a tree node at `/:foo/:bar', overwriting the previous value.
ok = khepri:put(StoreId, [foo, bar], new_value).
See also: put/4, khepri_adv:put_many/4.
create(PathPattern, Data) -> Ret
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Ret = khepri:minimal_ret()
Creates a tree node with the given payload.
Calling this function is the same as callingcreate(StoreId, PathPattern,
Data)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
create(StoreId, PathPattern, Data) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Ret = khepri:minimal_ret()
Creates a tree node with the given payload.
Calling this function is the same as callingcreate(StoreId, PathPattern,
Data, #{})
.
See also: create/4.
create(StoreId, PathPattern, Data, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Options = khepri:command_options() | khepri:tree_options() | khepri:put_options()
Ret = khepri:minimal_ret() | khepri_machine:async_ret()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree node to create.
Data
: the Erlang term or function to store, or a khepri_payload:payload()
structure.
Options
: command options.
returns: in the case of a synchronous call, ok
or an {error, Reason}
tuple; in the case of an asynchronous call, always ok
(the actual return
value may be sent by a message if a correlation ID was specified).
Creates a tree node with the given payload.
The behavior is the same as put/4
except that if the tree node
already exists, an {error, ?khepri_error(mismatching_node, Info)}
tuple is
returned.
PathPattern
is modified to include an
#if_node_exists{exists = false}
condition on its last component.
See also: compare_and_swap/5, put/4, update/4, khepri_adv:create/4.
update(PathPattern, Data) -> Ret
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Ret = khepri:minimal_ret()
Updates an existing tree node with the given payload.
Calling this function is the same as callingupdate(StoreId, PathPattern,
Data)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
update(StoreId, PathPattern, Data) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Ret = khepri:minimal_ret()
Updates an existing tree node with the given payload.
Calling this function is the same as callingupdate(StoreId, PathPattern,
Data, #{})
.
See also: update/4.
update(StoreId, PathPattern, Data, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Options = khepri:command_options() | khepri:tree_options() | khepri:put_options()
Ret = khepri:minimal_ret() | khepri_machine:async_ret()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree node to modify.
Data
: the Erlang term or function to store, or a khepri_payload:payload()
structure.
Options
: command options.
returns: in the case of a synchronous call, ok
or an {error, Reason}
tuple; in the case of an asynchronous call, always ok
(the actual return
value may be sent by a message if a correlation ID was specified).
Updates an existing tree node with the given payload.
The behavior is the same as put/4
except that if the tree node
already exists, an {error, ?khepri_error(mismatching_node, Info)}
tuple is
returned.
PathPattern
is modified to include an
#if_node_exists{exists = true}
condition on its last component.
See also: compare_and_swap/5, create/4, put/4, khepri_adv:update/4.
compare_and_swap(PathPattern, DataPattern, Data) -> Ret
PathPattern = khepri_path:pattern()
DataPattern = ets:match_pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Ret = khepri:minimal_ret()
Updates an existing tree node with the given payload only if its data matches the given pattern.
Calling this function is the same as callingcompare_and_swap(StoreId,
PathPattern, DataPattern, Data)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: compare_and_swap/4, compare_and_swap/5.
compare_and_swap(StoreId, PathPattern, DataPattern, Data) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
DataPattern = ets:match_pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Ret = khepri:minimal_ret()
Updates an existing tree node with the given payload only if its data matches the given pattern.
Calling this function is the same as callingcompare_and_swap(StoreId,
PathPattern, DataPattern, Data, #{})
.
See also: compare_and_swap/5.
compare_and_swap(StoreId, PathPattern, DataPattern, Data, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
DataPattern = ets:match_pattern()
Data = khepri_payload:payload() | khepri:data() | function()
Options = khepri:command_options() | khepri:tree_options() | khepri:put_options()
Ret = khepri:minimal_ret() | khepri_machine:async_ret()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree node to modify.
Data
: the Erlang term or function to store, or a khepri_payload:payload()
structure.
Options
: command options.
returns: in the case of a synchronous call, ok
or an {error, Reason}
tuple; in the case of an asynchronous call, always ok
(the actual return
value may be sent by a message if a correlation ID was specified).
Updates an existing tree node with the given payload only if its data matches the given pattern.
The behavior is the same as put/4
except that if the tree node
already exists, an {error, ?khepri_error(mismatching_node, Info)}
tuple is
returned.
PathPattern
is modified to include an
#if_data_matches{pattern = DataPattern}
condition on its last component.
See also: create/4, put/4, update/4, khepri_adv:compare_and_swap/5.
delete(PathPattern) -> Ret
PathPattern = khepri_path:pattern()
Ret = khepri:minimal_ret()
Deletes the tree node pointed to by the given path pattern.
Calling this function is the same as callingdelete(StoreId, PathPattern)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
delete(StoreId, PathPattern) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Ret = khepri:minimal_ret()
delete(PathPattern, Options) -> Ret
PathPattern = khepri_path:pattern()
Options = khepri:command_options() | khepri:tree_options()
Ret = khepri:minimal_ret()
Deletes the tree node pointed to by the given path pattern.
This function accepts the following two forms:delete(StoreId, PathPattern)
. Calling it is the same as calling
delete(StoreId, PathPattern, #{})
.delete(PathPattern, Options)
. Calling it is the same as calling
delete(StoreId, PathPattern, Options)
with the default store ID (see
khepri_cluster:get_default_store_id/0
).See also: delete/3.
delete(StoreId, PathPattern, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Options = khepri:command_options() | khepri:tree_options()
Ret = khepri:minimal_ret() | khepri_machine:async_ret()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the node to delete.
Options
: command options.
returns: in the case of a synchronous call, ok
or an {error, Reason}
tuple; in the case of an asynchronous call, always ok
(the actual return
value may be sent by a message if a correlation ID was specified).
Deletes the tree node pointed to by the given path pattern.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
The PathPattern
must target a specific tree node. In other words, deleting
many nodes is denied. That fact is checked before the tree node is looked
up: so if a condition in the path could potentially match several nodes, an
exception is raised, even though only one tree node would match at the time.
If you want to delete multiple nodes at once, use delete_many/3
.
%% Delete the tree node at `/:foo/:bar'.
ok = khepri:delete(StoreId, [foo, bar]).
See also: delete_many/3, khepri_adv:delete/3.
delete_many(PathPattern) -> Ret
PathPattern = khepri_path:pattern()
Ret = khepri:minimal_ret()
Deletes all tree nodes matching the given path pattern.
Calling this function is the same as callingdelete_many(StoreId,
PathPattern)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: delete_many/2, delete_many/3.
delete_many(StoreId, PathPattern) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Ret = khepri:minimal_ret()
delete_many(PathPattern, Options) -> Ret
PathPattern = khepri_path:pattern()
Options = khepri:command_options() | khepri:tree_options()
Ret = khepri:minimal_ret()
Deletes all tree nodes matching the given path pattern.
This function accepts the following two forms:delete_many(StoreId, PathPattern)
. Calling it is the same as calling
delete(StoreId, PathPattern, #{})
.delete_many(PathPattern, Options)
. Calling it is the same as calling
delete(StoreId, PathPattern, Options)
with the default store ID (see
khepri_cluster:get_default_store_id/0
).See also: delete_many/3.
delete_many(StoreId, PathPattern, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Options = khepri:command_options() | khepri:tree_options()
Ret = khepri:minimal_ret() | khepri_machine:async_ret()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the nodes to delete.
Options
: command options.
returns: in the case of a synchronous call, ok
or an {error, Reason}
tuple; in the case of an asynchronous call, always ok
(the actual return
value may be sent by a message if a correlation ID was specified).
Deletes all tree nodes matching the given path pattern.
The PathPattern
can be provided as a native path pattern (a list of tree
node names and conditions) or as a string. See khepri_path:from_string/1
.
%% Delete all nodes in the tree.
ok = khepri:delete_many(StoreId, [?KHEPRI_WILDCARD_STAR]).
See also: delete/3.
clear_payload(PathPattern) -> Ret
PathPattern = khepri_path:pattern()
Ret = khepri:minimal_ret()
Deletes the payload of the tree node pointed to by the given path pattern.
Calling this function is the same as callingclear_payload(StoreId,
PathPattern)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: clear_payload/2, clear_payload/3.
clear_payload(StoreId, PathPattern) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Ret = khepri:minimal_ret()
Deletes the payload of the tree node pointed to by the given path pattern.
Calling this function is the same as callingclear_payload(StoreId,
PathPattern, #{})
.
See also: clear_payload/3.
clear_payload(StoreId, PathPattern, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Options = khepri:command_options() | khepri:tree_options() | khepri:put_options()
Ret = khepri:minimal_ret() | khepri_machine:async_ret()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree node to modify.
Options
: command options.
returns: in the case of a synchronous call, ok
or an {error, Reason}
tuple; in the case of an asynchronous call, always ok
(the actual return
value may be sent by a message if a correlation ID was specified).
Deletes the payload of the tree node pointed to by the given path pattern.
In other words, the payload is set tokhepri_payload:no_payload()
.
Otherwise, the behavior is that of put/4
.
See also: put/4, khepri_adv:clear_payload/3.
clear_many_payloads(PathPattern) -> Ret
PathPattern = khepri_path:pattern()
Ret = khepri:minimal_ret()
Deletes the payload of all tree nodes matching the given path pattern.
Calling this function is the same as callingclear_many_payloads(StoreId,
PathPattern)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: clear_many_payloads/2, clear_many_payloads/3.
clear_many_payloads(StoreId, PathPattern) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Ret = khepri:minimal_ret()
Deletes the payload of all tree nodes matching the given path pattern.
Calling this function is the same as callingclear_many_payloads(StoreId,
PathPattern, #{})
.
See also: clear_many_payloads/3.
clear_many_payloads(StoreId, PathPattern, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Options = khepri:command_options() | khepri:tree_options() | khepri:put_options()
Ret = khepri:minimal_ret() | khepri_machine:async_ret()
StoreId
: the name of the Khepri store.
PathPattern
: the path (or path pattern) to the tree nodes to modify.
Options
: command options.
returns: in the case of a synchronous call, ok
or an {error, Reason}
tuple; in the case of an asynchronous call, always ok
(the actual return
value may be sent by a message if a correlation ID was specified).
Deletes the payload of all tree nodes matching the given path pattern.
In other words, the payload is set tokhepri_payload:no_payload()
.
Otherwise, the behavior is that of put/4
.
See also: delete_many/3, put/4, khepri_adv:clear_many_payloads/3.
register_trigger(TriggerId, EventFilter, StoredProcPath) -> Ret
TriggerId = trigger_id()
EventFilter = khepri_evf:event_filter() | khepri_path:pattern()
StoredProcPath = khepri_path:path()
Ret = ok | error()
Registers a trigger.
Calling this function is the same as callingregister_trigger(StoreId,
TriggerId, EventFilter, StoredProcPath)
with the default store ID (see
khepri_cluster:get_default_store_id/0
).
See also: register_trigger/4.
register_trigger(StoreId, TriggerId, EventFilter, StoredProcPath) -> Ret
StoreId = khepri:store_id()
TriggerId = trigger_id()
EventFilter = khepri_evf:event_filter() | khepri_path:pattern()
StoredProcPath = khepri_path:path()
Ret = ok | error()
register_trigger(TriggerId, EventFilter, StoredProcPath, Options) -> Ret
TriggerId = trigger_id()
EventFilter = khepri_evf:event_filter() | khepri_path:pattern()
StoredProcPath = khepri_path:path()
Options = command_options() | khepri:tree_options()
Ret = ok | error()
Registers a trigger.
This function accepts the following two forms:register_trigger(StoreId, TriggerId, EventFilter, StoredProcPath)
.
Calling it is the same as calling register_trigger(StoreId, TriggerId,
EventFilter, StoredProcPath, #{})
.register_trigger(TriggerId, EventFilter, StoredProcPath, Options)
.
Calling it is the same as calling register_trigger(StoreId, TriggerId,
EventFilter, StoredProcPath, Options)
with the default store ID (see
khepri_cluster:get_default_store_id/0
).See also: register_trigger/5.
register_trigger(StoreId, TriggerId, EventFilter, StoredProcPath, Options) -> Ret
StoreId = khepri:store_id()
TriggerId = trigger_id()
EventFilter = khepri_evf:event_filter() | khepri_path:pattern()
StoredProcPath = khepri_path:path()
Options = command_options() | khepri:tree_options()
Ret = ok | error()
StoreId
: the name of the Khepri store.
TriggerId
: the name of the trigger.
EventFilter
: the event filter used to associate an event with a
stored procedure.
StoredProcPath
: the path to the stored procedure to execute when the
corresponding event occurs.
returns: ok
if the trigger was registered, an {error, Reason}
tuple
otherwise.
Registers a trigger.
A trigger is based on an event filter. It associates an event with a stored procedure. When an event matching the event filter is emitted, the stored procedure is executed.
The following event filters are documented by khepri_evf:event_filter()
.
Here are examples of event filters:
%% An event filter can be explicitly created using the `khepri_evf'
%% module. This is possible to specify properties at the same time.
EventFilter = khepri_evf:tree([stock, wood, <<"oak">>], %% Required
#{on_actions => [delete], %% Optional
priority => 10}). %% Optional
%% For ease of use, some terms can be automatically converted to an event
%% filter. In this example, a Unix-like path can be used as a tree event
%% filter.
EventFilter = "/:stock/:wood/oak".
The stored procedure is expected to accept a single argument. This argument is a map containing the event properties. Here is an example:
my_stored_procedure(Props) ->
#{path := Path},
on_action => Action} = Props.
The stored procedure is executed on the leader's Erlang node.
It is guaranteed to run at least once. It could be executed multiple times if the Ra leader changes, therefore the stored procedure must be idempotent.register_projection(PathPattern, Projection) -> Ret
PathPattern = khepri_path:pattern()
Projection = khepri_projection:projection()
Ret = ok | khepri:error()
Registers a projection.
Calling this function is the same as callingregister_projection(StoreId, PathPattern, Projection)
with the default
store ID (see khepri_cluster:get_default_store_id/0
).
See also: register_projection/3.
register_projection(StoreId, PathPattern, Projection) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Projection = khepri_projection:projection()
Ret = ok | khepri:error()
register_projection(PathPattern, Projection, Options) -> Ret
PathPattern = khepri_path:pattern()
Projection = khepri_projection:projection()
Options = khepri:command_options()
Ret = ok | khepri:error()
Registers a projection.
This function accepts the following two forms:register_projection(StoreId, PathPattern, Projection)
. Calling it is
the same as calling register_projection(StoreId, PathPattern, Projection,
#{})
.register_projection(PathPattern, Projection, Options)
. Calling it is
the same as calling register_projection(StoreId, PathPattern, Projection,
Options)
with the default store ID (see khepri_cluster:get_default_store_id/0
).See also: register_projection/4.
register_projection(StoreId, PathPattern, Projection, Options) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Projection = khepri_projection:projection()
Options = khepri:command_options()
Ret = ok | khepri:error()
StoreId
: the name of the Khepri store.
PathPattern
: the pattern of tree nodes which the projection should
watch.
Projection
: the projection resource, created with
khepri_projection:new/3
.
Options
: command options for registering the projection.
returns: ok
if the projection was registered, an {error, Reason}
tuple
otherwise.
Registers a projection.
A projection is a replicated ETS cache which is kept up to date by
Khepri. See the khepri_projection
module-docs for more information
about projections.
This function associates a projection created with khepri_projection:new/3
with a pattern. Any changes to tree nodes matching
the provided pattern will be turned into records using the projection's
khepri_projection:projection_fun()
and then applied to the
projection's ETS table.
PathPattern
and are already in the store.
unregister_projections(Names) -> Ret
Names = all | [khepri_projection:name()]
Ret = ok | khepri:error()
Removes the given projections from the store.
Calling this function is the same as callingunregister_projections(StoreId, Names)
with the default store ID (see
khepri_cluster:get_default_store_id/0
).
See also: unregister_projections/2.
unregister_projections(StoreId, Names) -> Ret
StoreId = khepri:store_id()
Names = all | [khepri_projection:name()]
Ret = ok | khepri:error()
unregister_projections(Names, Options) -> Ret
Names = all | [khepri_projection:name()]
Options = khepri:command_options()
Ret = ok | khepri:error()
Removes the given projections from the store.
This function accepts the following two forms:unregister_projections(StoreId, Names)
. Calling it is the same as
calling unregister_projections(StoreId, Names, #{})
.unregister_projections(Names, Options)
. Calling it is the same as
calling unregister_projections(StoreId, Names, Options)
with
the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: unregister_projections/3.
unregister_projections(StoreId, Names, Options) -> Ret
StoreId = khepri:store_id()
Names = all | [khepri_projection:name()]
Options = khepri:command_options()
Ret = ok | khepri:error()
StoreId
: the name of the Khepri store.
Names
: the names of projections to unregister or the atom all
to
remove all projections.
Options
: command options for unregistering the projections.
returns: ok
if the projections were unregistered, an {error, Reason}
tuple otherwise.
Removes the given projections from the store.
Names
may either be a list of projection names to remove or the atom
all
. When all
is passed, every projection in the store is removed.
See also: khepri_adv:unregister_projections/3.
has_projection(ProjectionName) -> Ret
ProjectionName = khepri_projection:name()
Ret = boolean() | khepri:error()
Determines whether the store has a projection registered with the given name.
Calling this function is the same as callinghas_projection(StoreId, ProjectionName)
with the default store ID
(see khepri_cluster:get_default_store_id/0
).
See also: has_projection/2.
has_projection(StoreId, ProjectionName) -> Ret
StoreId = khepri:store_id()
ProjectionName = khepri_projection:name()
Ret = boolean() | khepri:error()
has_projection(ProjectionName, Options) -> Ret
ProjectionName = khepri_projection:name()
Options = khepri:query_options()
Ret = boolean() | khepri:error()
Determines whether the store has a projection registered with the given name.
This function accepts the following two forms:has_projection(StoreId, ProjectionName)
. Calling it is the same
as calling has_projection(StoreId, ProjectionName, #{})
.has_projection(ProjectionName, Options)
. Calling it is the same
as calling has_projection(StoreId, ProjectionName, Options)
with
the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: has_projection/3.
has_projection(StoreId, ProjectionName, Options) -> Ret
StoreId = khepri:store_id()
ProjectionName = khepri_projection:name()
Options = khepri:query_options()
Ret = boolean() | khepri:error()
StoreId
: the name of the Khepri store.
ProjectionName
: the name of the projection to has as passed to
khepri_projection:new/3
.
Options
: query options.
returns: true
if the store contains a projection registered with the given
name, false
if it does not, or an {error, Reason}
tuple if the query
failed.
Determines whether the store has a projection registered with the given name.
transaction(FunOrPath) -> Ret
FunOrPath = Fun | PathPattern
Fun = khepri_tx:tx_fun()
PathPattern = khepri_path:pattern()
Ret = khepri_machine:tx_ret()
Runs a transaction and returns its result.
Calling this function is the same as callingtransaction(FunOrPath, [])
with the default store ID.
See also: transaction/2.
transaction(StoreId, FunOrPath) -> Ret
StoreId = store_id()
FunOrPath = Fun | PathPattern
Fun = khepri_tx:tx_fun()
PathPattern = khepri_path:pattern()
Ret = khepri_machine:tx_ret()
transaction(FunOrPath, Args) -> Ret
FunOrPath = Fun | PathPattern
Fun = khepri_tx:tx_fun()
PathPattern = khepri_path:pattern()
Args = list()
Ret = khepri_machine:tx_ret()
transaction(FunOrPath, ReadWriteOrOptions) -> Ret
FunOrPath = Fun | PathPattern
Fun = khepri_tx:tx_fun()
PathPattern = khepri_path:pattern()
ReadWriteOrOptions = ReadWrite | Options
ReadWrite = ro | rw | auto
Options = command_options() | query_options()
Ret = khepri_machine:tx_ret() | khepri_machine:async_ret()
Runs a transaction and returns its result.
This function accepts the following two forms:transaction(StoreId, FunOrPath)
. Calling it is the same as calling
transaction(StoreId, FunOrPath, [])
.transaction(FunOrPath, Args)
. Calling it is the same as calling
transaction(StoreId, FunOrPath, Args)
with the default store ID.transaction(FunOrPath, ReadWriteOrOptions)
. Calling it is the same as
calling transaction(StoreId, FunOrPath, [], ReadWriteOrOptions)
with the
default store ID.See also: transaction/3.
transaction(StoreId, FunOrPath, Args) -> Ret
StoreId = store_id()
FunOrPath = Fun | PathPattern
Fun = khepri_tx:tx_fun()
PathPattern = khepri_path:pattern()
Args = list()
Ret = khepri_machine:tx_ret()
transaction(StoreId, FunOrPath, ReadWriteOrOptions) -> Ret
StoreId = store_id()
FunOrPath = Fun | PathPattern
Fun = khepri_tx:tx_fun()
PathPattern = khepri_path:pattern()
ReadWriteOrOptions = ReadWrite | Options
ReadWrite = ro | rw | auto
Options = command_options() | query_options()
Ret = khepri_machine:tx_ret() | khepri_machine:async_ret()
transaction(FunOrPath, Args, ReadWriteOrOptions) -> Ret
FunOrPath = Fun | PathPattern
Fun = khepri_tx:tx_fun()
PathPattern = khepri_path:pattern()
Args = list()
ReadWriteOrOptions = ReadWrite | Options
ReadWrite = ro | rw | auto
Options = command_options() | query_options()
Ret = khepri_machine:tx_ret() | khepri_machine:async_ret()
transaction(FunOrPath, ReadWrite, Options) -> Ret
FunOrPath = Fun | PathPattern
Fun = khepri_tx:tx_fun()
PathPattern = khepri_path:pattern()
ReadWrite = ro | rw | auto
Options = command_options() | query_options()
Ret = khepri_machine:tx_ret() | khepri_machine:async_ret()
Runs a transaction and returns its result.
This function accepts the following two forms:transaction(StoreId, FunOrPath, Args)
. Calling it is the same as
calling transaction(StoreId, FunOrPath, Args, auto)
.transaction(StoreId, FunOrPath, ReadWriteOrOptions)
. Calling it is
the same as calling transaction(StoreId, FunOrPath, [],
ReadWriteOrOptions)
.transaction(FunOrPath, Args, ReadWriteOrOptions)
. Calling it is the
same as calling transaction(StoreId, FunOrPath, Args, ReadWriteOrOptions)
with the default store ID.See also: transaction/4.
transaction(StoreId, FunOrPath, Args, ReadWrite) -> Ret
StoreId = store_id()
FunOrPath = Fun | PathPattern
Fun = khepri_tx:tx_fun()
PathPattern = khepri_path:pattern()
Args = list()
ReadWrite = ro | rw | auto
Ret = khepri_machine:tx_ret()
transaction(StoreId, FunOrPath, Args, Options) -> Ret
StoreId = store_id()
FunOrPath = Fun | PathPattern
Fun = khepri_tx:tx_fun()
PathPattern = khepri_path:pattern()
Args = list()
Options = command_options() | query_options()
Ret = khepri_machine:tx_ret() | khepri_machine:async_ret()
transaction(StoreId, FunOrPath, ReadWrite, Options) -> Ret
StoreId = store_id()
FunOrPath = Fun | PathPattern
Fun = khepri_tx:tx_fun()
PathPattern = khepri_path:pattern()
ReadWrite = ro | rw | auto
Options = command_options() | query_options()
Ret = khepri_machine:tx_ret() | khepri_machine:async_ret()
transaction(FunOrPath, Args, ReadWrite, Options) -> Ret
FunOrPath = Fun | PathPattern
Fun = khepri_tx:tx_fun()
PathPattern = khepri_path:pattern()
Args = list()
ReadWrite = ro | rw | auto
Options = command_options() | query_options()
Ret = khepri_machine:tx_ret() | khepri_machine:async_ret()
Runs a transaction and returns its result.
This function accepts the following three forms:transaction(StoreId, FunOrPath, Args, ReadWrite)
. Calling it is the
same as calling transaction(StoreId, FunOrPath, Args, ReadWrite,
#{})
.transaction(StoreId, FunOrPath, Args, Options)
. Calling it is the
same as calling transaction(StoreId, FunOrPath, Args, auto,
Options)
.transaction(FunOrPath, Args, ReadWrite, Options)
. Calling it is the
same as calling transaction(StoreId, FunOrPath, Args, ReadWrite, Options)
with the default store ID.See also: transaction/5.
transaction(StoreId, FunOrPath, Args, ReadWrite, Options) -> Ret
StoreId = store_id()
FunOrPath = Fun | PathPattern
Fun = khepri_tx:tx_fun()
PathPattern = khepri_path:pattern()
Args = list()
ReadWrite = ro | rw | auto
Options = khepri:command_options() | khepri:query_options()
Ret = khepri_machine:tx_ret() | khepri_machine:async_ret()
StoreId
: the name of the Khepri store.
FunOrPath
: an arbitrary anonymous function or a path pattern pointing
to a stored procedure.
Args
: a list of arguments to pass to FunOrPath
.
ReadWrite
: the read/write or read-only nature of the transaction.
Options
: command options such as the command type.
returns: in the case of a synchronous transaction, {ok, Result}
where
Result
is the return value of FunOrPath
, or {error, Reason}
if the
anonymous function was aborted; in the case of an asynchronous transaction,
always ok
(the actual return value may be sent by a message if a
correlation ID was specified).
Runs a transaction and returns its result.
Fun
is an arbitrary anonymous function which takes the content of Args
as its arguments. In other words, the length of Args
must correspond to
the arity of Fun
.
Instead of Fun
, PathPattern` can be passed. It must point to an existing
stored procedure. The length to `Args
must correspond to the arity of that
stored procedure.
The ReadWrite
flag determines what the Fun
anonymous function is
allowed to do and in which context it runs:
ReadWrite
is ro
, Fun
can do whatever it wants, except modify
the content of the store. In other words, uses of khepri_tx:put/2
or khepri_tx:delete/1
are forbidden and will abort the function.
Fun
is executed from a process on the leader Ra member.ReadWrite
is rw
, Fun
can use the khepri_tx
transaction
API as well as any calls to other modules as long as those functions or what
they do is permitted. See khepri_tx
for more details. If Fun
does
or calls something forbidden, the transaction will be aborted. Fun
is
executed in the context of the state machine process on each Ra
members.ReadWrite
is auto
, Fun
is analyzed to determine if it calls
khepri_tx:put/2
or khepri_tx:delete/1
, or uses any denied
operations for a read/write transaction. If it does, this is the same as
setting ReadWrite
to true. Otherwise, this is the equivalent of setting
ReadWrite
to false.When using PathPattern
, a ReadWrite
of auto
is synonymous of rw
.
Options
is relevant for both read-only and read-write transactions
(including audetected ones). However note that both types expect different
options.
FunOrPath
can be any term. That result is returned in an
{ok, Result}
tuple if the transaction is synchronous. The result is sent
by message if the transaction is asynchronous and a correlation ID was
specified.
fence() -> Ret
Ret = ok | khepri:error()
Blocks until all updates received by the cluster leader are applied locally.
Calling this function is the same as callingfence(StoreId)
with the
default store ID (see khepri_cluster:get_default_store_id/0
).
fence(Timeout::StoreId | Timeout) -> Ret
StoreId = khepri:store_id()
Timeout = timeout()
Ret = ok | khepri:error()
Blocks until all updates received by the cluster leader are applied locally.
This function accepts the following two forms:fence(StoreId)
. Calling it is the same as calling fence(StoreId,
Timeout)
with the default timeout (see khepri_app:get_default_timeout/0
).fence(Timeout)
. Calling it is the same as calling fence(StoreId,
Timeout)
with the default store ID (see khepri_cluster:get_default_store_id/0
).See also: fence/2.
fence(StoreId, Timeout) -> Ret
StoreId = khepri:store_id()
Timeout = timeout()
Ret = ok | khepri:error()
StoreId
: the name of the Khepri store.
Timeout
: the time limit after which the call returns with an error.
returns: ok
or an {error, Reason}
tuple.
Blocks until all updates received by the cluster leader are applied locally.
This ensures that a subsequent query will see the result of synchronous and asynchronous updates.
This can't work however if:reply_from => local
command option is overridden by
something else.handle_async_ret(RaEvent) -> Ret
RaEvent = ra_server_proc:ra_event()
Ret = [{CorrelationId, AsyncRet}, ...]
CorrelationId = ra_server:command_correlation()
AsyncRet = khepri:async_ret()
Handles the Ra event sent for asynchronous call results.
Calling this function is the same as callinghandle_async_ret(StoreId, RaEvent)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: handle_async_ret/2.
handle_async_ret(StoreId, RaEvent) -> Ret
StoreId = khepri:store_id()
RaEvent = ra_server_proc:ra_event()
Ret = [{CorrelationId, AsyncRet}, ...]
CorrelationId = ra_server:command_correlation()
AsyncRet = khepri:async_ret()
Handles the Ra event sent for asynchronous call results.
When sending commands with async
command_options()
, the calling
process will receive Ra events with the following structure:
{ra_event, CurrentLeader, {applied, [{Correlation1, Reply1}, ...]}}
or
{ra_event,
FromId,
{rejected, {not_leader, Leader | undefined, Correlation}}}
The first event acknowledges all commands handled in a batch while the second is sent per-command when commands are sent against a non-leader member.
These events should be passed to this function in order to map the return values from the async commands and to update leader information. This function does not handle retrying rejected commands or return values from applied commands - the caller is responsible for those tasks.
Example:ok = khepri:put(StoreId, [stock, wood, <<"oak">>], 200, #{async => 1}),
ok = khepri:put(StoreId, [stock, wood, <<"maple">>], 150, #{async => 2}),
RaEvent = receive {ra_event, _, _} = Event -> Event end,
?assertMatch(
[{1, {ok, #{[stock, wood, <<"oak">>] => _}}},
{2, {ok, #{[stock, wood, <<"maple">>] => _}}}],
khepri:handle_async_ret(RaEvent)).
See also: async_option(), ra:pipeline_command/4.
'get!'(PathPattern) -> Payload
PathPattern = khepri_path:pattern()
Payload = khepri:unwrapped_payload_ret()
'get!'(StoreId, PathPattern) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Payload = khepri:unwrapped_payload_ret()
'get!'(PathPattern, Options) -> Payload
PathPattern = khepri_path:pattern()
Options = query_options() | khepri:tree_options()
Payload = khepri:unwrapped_payload_ret()
'get!'(StoreId, PathPattern, Options) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Options = query_options() | khepri:tree_options()
Payload = khepri:unwrapped_payload_ret()
'get_or!'(PathPattern, Default) -> Payload
PathPattern = khepri_path:pattern()
Default = khepri:data()
Payload = khepri:unwrapped_payload_ret()
'get_or!'(StoreId, PathPattern, Default) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Default = khepri:data()
Payload = khepri:unwrapped_payload_ret()
'get_or!'(PathPattern, Default, Options) -> Payload
PathPattern = khepri_path:pattern()
Default = khepri:data()
Options = query_options() | khepri:tree_options()
Payload = khepri:unwrapped_payload_ret()
'get_or!'(StoreId, PathPattern, Default, Options) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Default = khepri:data()
Options = query_options() | khepri:tree_options()
Payload = khepri:unwrapped_payload_ret()
'get_many!'(PathPattern) -> Payload
PathPattern = khepri_path:pattern()
Payload = khepri:unwrapped_many_payloads_ret()
'get_many!'(StoreId, PathPattern) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Payload = khepri:unwrapped_many_payloads_ret()
'get_many!'(PathPattern, Options) -> Payload
PathPattern = khepri_path:pattern()
Options = query_options() | khepri:tree_options()
Payload = khepri:unwrapped_many_payloads_ret()
'get_many!'(StoreId, PathPattern, Options) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Options = query_options() | khepri:tree_options()
Payload = khepri:unwrapped_many_payloads_ret()
'get_many_or!'(PathPattern, Default) -> Payload
PathPattern = khepri_path:pattern()
Default = khepri:data()
Payload = khepri:unwrapped_many_payloads_ret()
'get_many_or!'(StoreId, PathPattern, Default) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Default = khepri:data()
Payload = khepri:unwrapped_many_payloads_ret()
'get_many_or!'(PathPattern, Default, Options) -> Payload
PathPattern = khepri_path:pattern()
Default = khepri:data()
Options = query_options() | khepri:tree_options()
Payload = khepri:unwrapped_many_payloads_ret()
'get_many_or!'(StoreId, PathPattern, Default, Options) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Default = khepri:data()
Options = query_options() | khepri:tree_options()
Payload = khepri:unwrapped_many_payloads_ret()
'exists!'(PathPattern) -> Exists
PathPattern = khepri_path:pattern()
Exists = boolean()
'exists!'(StoreId, PathPattern) -> Exists
StoreId = store_id()
PathPattern = khepri_path:pattern()
Exists = boolean()
'exists!'(PathPattern, Options) -> Exists
PathPattern = khepri_path:pattern()
Options = query_options() | khepri:tree_options()
Exists = boolean()
'exists!'(StoreId, PathPattern, Options) -> Exists
StoreId = store_id()
PathPattern = khepri_path:pattern()
Options = query_options() | khepri:tree_options()
Exists = boolean()
'has_data!'(PathPattern) -> HasData
PathPattern = khepri_path:pattern()
HasData = boolean()
'has_data!'(StoreId, PathPattern) -> HasData
StoreId = store_id()
PathPattern = khepri_path:pattern()
HasData = boolean()
'has_data!'(PathPattern, Options) -> HasData
PathPattern = khepri_path:pattern()
Options = query_options() | khepri:tree_options()
HasData = boolean()
'has_data!'(StoreId, PathPattern, Options) -> HasData
StoreId = store_id()
PathPattern = khepri_path:pattern()
Options = query_options() | khepri:tree_options()
HasData = boolean()
'is_sproc!'(PathPattern) -> IsSproc
PathPattern = khepri_path:pattern()
IsSproc = boolean()
'is_sproc!'(StoreId, PathPattern) -> IsSproc
StoreId = store_id()
PathPattern = khepri_path:pattern()
IsSproc = boolean()
'is_sproc!'(PathPattern, Options) -> IsSproc
PathPattern = khepri_path:pattern()
Options = query_options() | khepri:tree_options()
IsSproc = boolean()
'is_sproc!'(StoreId, PathPattern, Options) -> IsSproc
StoreId = store_id()
PathPattern = khepri_path:pattern()
Options = query_options() | khepri:tree_options()
IsSproc = boolean()
'count!'(PathPattern) -> Payload
PathPattern = khepri_path:pattern()
Payload = khepri:unwrapped_payload_ret()
'count!'(StoreId, PathPattern) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Payload = khepri:unwrapped_payload_ret()
'count!'(PathPattern, Options) -> Payload
PathPattern = khepri_path:pattern()
Options = query_options() | khepri:tree_options()
Payload = khepri:unwrapped_payload_ret()
'count!'(StoreId, PathPattern, Options) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Options = query_options() | khepri:tree_options()
Payload = khepri:unwrapped_payload_ret()
'put!'(PathPattern, Data) -> Payload
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | data() | function()
Payload = khepri:unwrapped_minimal_ret()
'put!'(StoreId, PathPattern, Data) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | data() | function()
Payload = khepri:unwrapped_minimal_ret()
'put!'(StoreId, PathPattern, Data, Options) -> Ret
StoreId = store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | data() | function()
Options = khepri:command_options() | khepri:tree_options() | khepri:put_options()
Ret = khepri:unwrapped_minimal_ret() | khepri_machine:async_ret()
'put_many!'(PathPattern, Data) -> Payload
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | data() | function()
Payload = khepri:unwrapped_minimal_ret()
'put_many!'(StoreId, PathPattern, Data) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | data() | function()
Payload = khepri:unwrapped_minimal_ret()
'put_many!'(StoreId, PathPattern, Data, Options) -> Ret
StoreId = store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | data() | function()
Options = khepri:command_options() | khepri:tree_options() | khepri:put_options()
Ret = khepri:unwrapped_minimal_ret() | khepri_machine:async_ret()
'create!'(PathPattern, Data) -> Payload
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | data() | function()
Payload = khepri:unwrapped_minimal_ret()
'create!'(StoreId, PathPattern, Data) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | data() | function()
Payload = khepri:unwrapped_minimal_ret()
'create!'(StoreId, PathPattern, Data, Options) -> Ret
StoreId = store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | data() | function()
Options = khepri:command_options() | khepri:tree_options() | khepri:put_options()
Ret = khepri:unwrapped_minimal_ret() | khepri_machine:async_ret()
'update!'(PathPattern, Data) -> Payload
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | data() | function()
Payload = khepri:unwrapped_minimal_ret()
'update!'(StoreId, PathPattern, Data) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | data() | function()
Payload = khepri:unwrapped_minimal_ret()
'update!'(StoreId, PathPattern, Data, Options) -> Ret
StoreId = store_id()
PathPattern = khepri_path:pattern()
Data = khepri_payload:payload() | data() | function()
Options = khepri:command_options() | khepri:tree_options() | khepri:put_options()
Ret = khepri:unwrapped_minimal_ret() | khepri_machine:async_ret()
'compare_and_swap!'(PathPattern, DataPattern, Data) -> Payload
PathPattern = khepri_path:pattern()
DataPattern = ets:match_pattern()
Data = khepri_payload:payload() | data() | function()
Payload = khepri:unwrapped_minimal_ret()
'compare_and_swap!'(StoreId, PathPattern, DataPattern, Data) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
DataPattern = ets:match_pattern()
Data = khepri_payload:payload() | data() | function()
Payload = khepri:unwrapped_minimal_ret()
'compare_and_swap!'(StoreId, PathPattern, DataPattern, Data, Options) -> Ret
StoreId = store_id()
PathPattern = khepri_path:pattern()
DataPattern = ets:match_pattern()
Data = khepri_payload:payload() | data() | function()
Options = khepri:command_options() | khepri:tree_options() | khepri:put_options()
Ret = khepri:unwrapped_minimal_ret() | khepri_machine:async_ret()
'delete!'(PathPattern) -> Payload
PathPattern = khepri_path:pattern()
Payload = khepri:unwrapped_minimal_ret()
'delete!'(StoreId, PathPattern) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Payload = khepri:unwrapped_minimal_ret()
'delete!'(PathPattern, Options) -> Ret
PathPattern = khepri_path:pattern()
Options = command_options() | khepri:tree_options()
Ret = khepri:unwrapped_minimal_ret() | khepri_machine:async_ret()
'delete!'(StoreId, PathPattern, Options) -> Ret
StoreId = store_id()
PathPattern = khepri_path:pattern()
Options = command_options() | khepri:tree_options()
Ret = khepri:unwrapped_minimal_ret() | khepri_machine:async_ret()
'delete_many!'(PathPattern) -> Payload
PathPattern = khepri_path:pattern()
Payload = khepri:unwrapped_minimal_ret()
'delete_many!'(StoreId, PathPattern) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Payload = khepri:unwrapped_minimal_ret()
'delete_many!'(PathPattern, Options) -> Ret
PathPattern = khepri_path:pattern()
Options = command_options() | khepri:tree_options()
Ret = khepri:unwrapped_minimal_ret() | khepri_machine:async_ret()
'delete_many!'(StoreId, PathPattern, Options) -> Ret
StoreId = store_id()
PathPattern = khepri_path:pattern()
Options = command_options() | khepri:tree_options()
Ret = khepri:unwrapped_minimal_ret() | khepri_machine:async_ret()
'clear_payload!'(PathPattern) -> Payload
PathPattern = khepri_path:pattern()
Payload = khepri:unwrapped_minimal_ret()
'clear_payload!'(StoreId, PathPattern) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Payload = khepri:unwrapped_minimal_ret()
'clear_payload!'(StoreId, PathPattern, Options) -> Ret
StoreId = store_id()
PathPattern = khepri_path:pattern()
Options = khepri:command_options() | khepri:tree_options() | khepri:put_options()
Ret = khepri:unwrapped_minimal_ret() | khepri_machine:async_ret()
'clear_many_payloads!'(PathPattern) -> Payload
PathPattern = khepri_path:pattern()
Payload = khepri:unwrapped_minimal_ret()
'clear_many_payloads!'(StoreId, PathPattern) -> Payload
StoreId = store_id()
PathPattern = khepri_path:pattern()
Payload = khepri:unwrapped_minimal_ret()
'clear_many_payloads!'(StoreId, PathPattern, Options) -> Ret
StoreId = store_id()
PathPattern = khepri_path:pattern()
Options = khepri:command_options() | khepri:tree_options() | khepri:put_options()
Ret = khepri:unwrapped_minimal_ret() | khepri_machine:async_ret()
export(Module, ModulePriv) -> Ret
Module = module()
ModulePriv = khepri_import_export:module_priv()
Ret = ok | {ok, ModulePriv} | {error, any()}
Exports a Khepri store using the Module
callback module.
export(StoreId, Module,
ModulePriv)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
export(StoreId::StoreId | PathPattern, Module, ModulePriv) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Module = module()
ModulePriv = khepri_import_export:module_priv()
Ret = ok | {ok, ModulePriv} | {error, any()}
Exports a Khepri store using the Module
callback module.
export(StoreId, Module, ModulePriv)
. Calling it is the same as
calling export(StoreId, "**", Module, ModulePriv)
.export(PathPattern, Module, ModulePriv)
. Calling it is the same as
calling export(StoreId, PathPattern, Module, ModulePriv)
with the default
store ID (see khepri_cluster:get_default_store_id/0
).See also: export/4.
export(StoreId, PathPattern, Module, ModulePriv) -> Ret
StoreId = khepri:store_id()
PathPattern = khepri_path:pattern()
Module = module()
ModulePriv = khepri_import_export:module_priv()
Ret = ok | {ok, ModulePriv} | {error, any()}
StoreId
: the name of the Khepri store.
PathPattern
: the path pattern matching the tree nodes to export.
Module
: the callback module to use to export.
ModulePriv
: arguments passed to Module:open_write/1
.
returns: ok
or an {ok, Term}
tuple if the export succeeded (the actual
return value depends on whether the callback module wants to return anything
to the caller), or an {error, Reason}
tuple if it failed.
Exports a Khepri store using the Module
callback module.
The PathPattern
allows to filter which tree nodes are exported. The path
pattern can be provided as a native path pattern (a list of tree node names
and conditions) or as a string. See khepri_path:from_string/1
.
Module
is the callback module called to perform the actual export. It
must conform to the Mnesia Backup & Restore API. See khepri_import_export
for more details.
ModulePriv
is the term passed to Module:open_write/1
.
khepri_export_erlang
as
the callback module
ok = khepri:export(StoreId, khepri_export_erlang, "export-1.erl").
Example: export a subset of the Khepri store
ok = khepri:export(
StoreId,
"/:stock/:wood/**",
khepri_export_erlang,
"export-wood-stock-1.erl").
See also: import/3.
import(Module, ModulePriv) -> Ret
Module = module()
ModulePriv = khepri_import_export:module_priv()
Ret = ok | {ok, ModulePriv} | {error, any()}
Imports a previously exported set of tree nodes using the Module
callback module.
import(StoreId, Module,
ModulePriv)
with the default store ID (see khepri_cluster:get_default_store_id/0
).
See also: import/3.
import(StoreId, Module, ModulePriv) -> Ret
StoreId = khepri:store_id()
Module = module()
ModulePriv = khepri_import_export:module_priv()
Ret = ok | {ok, ModulePriv} | {error, any()}
StoreId
: the name of the Khepri store.
Module
: the callback module to use to import.
ModulePriv
: arguments passed to Module:open_read/1
.
returns: ok
or an {ok, Term}
tuple if the import succeeded (the actual
return value depends on whether the callback module wants to return anything
to the caller), or an {error, Reason}
tuple if it failed.
Imports a previously exported set of tree nodes using the Module
callback module.
Module
is the callback module called to perform the actual import. It
must conform to the Mnesia Backup & Restore API. See khepri_import_export
for more details.
ModulePriv
is the term passed to Module:open_read/1
.
Importing something doesn't delete existing tree nodes. The caller is responsible for deleting the existing content of a store if he needs to.
Example: import a set of tree nodes usingkhepri_export_erlang
as
the callback module
ok = khepri:import(StoreId, khepri_export_erlang, "export-1.erl").
See also: export/3.
info() -> ok
Lists the running stores on stdout.
Lists the content of specified store on stdout.
info(StoreId, Options) -> ok
StoreId = khepri:store_id()
Options = khepri:query_options()
StoreId
: the name of the Khepri store.
Options
: query options.
Lists the content of specified store on stdout.
Generated by EDoc