reckon_db_dcb_paths (reckon_db v3.1.1)

View Source

DCB Khepri path helpers.

DCB events live under [events, ?DCB_STREAM] and are mirrored under [by_tag, Tag, SeqKey] for every tag they carry. The mirror entries are the tag index: a subtree iteration on [by_tag, Tag, *] returns all seq keys for that tag, lexicographically (numerically) sorted.

Seq keys are fixed-width zero-padded decimal binaries (see ?DCB_SEQ_KEY_WIDTH), so lists:max/1 on a list of seq keys returns the highest, and Key > Cutoff is a lex comparison that matches the numeric comparison.

All functions here are PURE; safe to call from inside a khepri:transaction/2 body.

Summary

Functions

Path to a tag-index entry: [by_tag, <<"email:foo@bar">>, <<"00000000000000000042">>]

Pattern matching every seq under a tag (subtree wildcard). Use with khepri_tx:get_many/1 inside a transaction.

Path to the event payload at a given seq: [events, <<"_dcb">>, <<"00000000000000000042">>]

Decode a seq_key binary back to its integer.

Convert a non-negative integer to a fixed-width zero-padded decimal binary (?DCB_SEQ_KEY_WIDTH digits).

Functions

by_tag_path(Tag, Seq)

-spec by_tag_path(binary(), non_neg_integer()) -> [term()].

Path to a tag-index entry: [by_tag, <<"email:foo@bar">>, <<"00000000000000000042">>]

by_tag_pattern(Tag)

-spec by_tag_pattern(binary()) -> [term()].

Pattern matching every seq under a tag (subtree wildcard). Use with khepri_tx:get_many/1 inside a transaction.

event_path(Seq)

-spec event_path(non_neg_integer()) -> [term()].

Path to the event payload at a given seq: [events, <<"_dcb">>, <<"00000000000000000042">>]

seq_from_key(Bin)

-spec seq_from_key(binary()) -> non_neg_integer().

Decode a seq_key binary back to its integer.

seq_key(Seq)

-spec seq_key(non_neg_integer()) -> binary().

Convert a non-negative integer to a fixed-width zero-padded decimal binary (?DCB_SEQ_KEY_WIDTH digits).

Invariants: - byte_size(seq_key(N)) == ?DCB_SEQ_KEY_WIDTH for all valid N - seq_key(A) =< seq_key(B) iff A =< B (lex == numeric) - seq_from_key(seq_key(N)) == N (roundtrip)