Public API for the DCB event store backed by FoundationDB.
This module wraps the raw Rust NIF bindings with idiomatic Elixir defaults and option handling.
See the README for data structure shapes (event, query, condition).
Summary
Functions
Appends events to the store.
Returns the position stored under name for the given named cursor.
Opens a store connection scoped to namespace.
Reads events matching query from the store.
Returns all events in the store, in insertion order.
Persists position under name as a named cursor.
Subscribes the calling process to store change notifications.
Functions
Appends events to the store.
Optionally accepts conditions for optimistic concurrency: the append
fails if any matching events exist after the position specified in each condition.
Example
events = [%{type_name: "UserCreated", tags: ["user-1"], data: <<>>}]
{:ok, position} = Dcb.Store.append(store, events)
condition = %{query: %{items: [%{types: ["UserCreated"], tags: ["user-1"]}]}, after: nil}
{:ok, position} = Dcb.Store.append(store, events, [condition])
Returns the position stored under name for the given named cursor.
Opens a store connection scoped to namespace.
Options
:cluster_file- path to the FDB cluster file (default:nil, uses the default cluster file)
Example
{:ok, store} = Dcb.Store.open("my_namespace")
{:ok, store} = Dcb.Store.open("my_namespace", cluster_file: "/etc/foundationdb/fdb.cluster")
Reads events matching query from the store.
Options
:limit- max events to return,0means unlimited (default:0):after- only return events after this position (default:nil):reverse- return events in reverse order (default:false)
Example
query = %{items: [%{types: ["UserCreated"], tags: ["user-1"]}]}
{:ok, events} = Dcb.Store.read(store, query)
{:ok, events} = Dcb.Store.read(store, query, limit: 50, after: position)
Returns all events in the store, in insertion order.
Persists position under name as a named cursor.
Subscribes the calling process to store change notifications.
Sends {:dcb_store_changed, store} to self() whenever new events are appended.
The watch is one-shot; call watch/1 again after receiving the message to re-subscribe.