reckon_db_log_backend behaviour (reckon_db v2.2.0)

View Source

Summary

Types

direction/0

-type direction() :: forward | backward.

event/0

-type event() :: term().

#event{} — avoiding circular include

expected_version/0

-type expected_version() :: integer().

new_event/0

-type new_event() ::
          #{event_type := binary(),
            data := map() | binary(),
            metadata => map(),
            tags => [binary()],
            event_id => binary()}.

offset/0

-type offset() :: non_neg_integer().

state/0

-type state() :: term().

store_id/0

-type store_id() :: atom().

stream_id/0

-type stream_id() :: binary().

version/0

-type version() :: non_neg_integer().

Callbacks

append_batch/2

(optional)
-callback append_batch(state(), [{stream_id(), expected_version(), [new_event()]}]) ->
                          {ok, [{stream_id(), {ok, version()} | {error, term()}}]} | {error, term()}.

append_events/4

-callback append_events(state(), stream_id(), expected_version(), [new_event()]) ->
                           {ok, version()} |
                           {error, {wrong_expected_version, version()}} |
                           {error, Reason :: term()}.

close/1

-callback close(state()) -> ok.

compact/1

(optional)
-callback compact(state()) -> ok | {error, term()}.

delete_stream/2

-callback delete_stream(state(), stream_id()) -> ok | {error, stream_not_found} | {error, term()}.

disk_bytes/1

(optional)
-callback disk_bytes(state()) -> {ok, non_neg_integer()} | {error, term()}.

has_events/1

-callback has_events(state()) -> boolean().

health/1

(optional)
-callback health(state()) -> ok | {error, term()}.

init/1

-callback init(Opts :: map()) -> {ok, state()} | {error, Reason :: term()}.

list_streams/1

-callback list_streams(state()) -> {ok, [stream_id()]} | {error, term()}.

read_all/3

-callback read_all(state(), offset(), Count :: pos_integer()) -> {ok, [event()]} | {error, term()}.

read_stream/5

-callback read_stream(state(),
                      stream_id(),
                      StartVersion :: non_neg_integer(),
                      Count :: pos_integer(),
                      direction()) ->
                         {ok, [event()]} | {error, term()}.

stream_exists/2

-callback stream_exists(state(), stream_id()) -> boolean().

stream_version/2

-callback stream_version(state(), stream_id()) ->
                            {ok, version()} | {error, stream_not_found} | {error, term()}.

truncate_stream/3

(optional)
-callback truncate_stream(state(), stream_id(), version()) -> ok | {error, term()}.