UmaDbClient.Builder (uma_db_client v0.7.5)

Copy Markdown

Convenience constructors for UmaDB proto message structs.

These are thin wrappers around the generated UmaDb.V1.* structs. You can always build structs directly if you prefer.

event/1 takes :data as raw bytes, so callers encode themselves:

Builder.event(type: "OrderPlaced", data: Jason.encode!(%{id: 1}))

To configure encoding and decoding once, see use UmaDbClient.

Summary

Functions

Builds an UmaDb.V1.AppendCondition for optimistic concurrency.

Builds an UmaDb.V1.Event struct from a keyword list.

Builds a UmaDb.V1.Query from a list of UmaDb.V1.QueryItem structs.

Builds a UmaDb.V1.QueryItem that matches events by type and/or tag.

Builds an UmaDb.V1.TrackingInfo to advance a named tracking cursor on append.

Functions

append_condition(opts \\ [])

@spec append_condition(keyword()) :: UmaDb.V1.AppendCondition.t()

Builds an UmaDb.V1.AppendCondition for optimistic concurrency.

Options

  • :fail_if_events_matchUmaDb.V1.Query; the append fails if any matching event exists
  • :after — only consider events after this position when evaluating the condition

event(opts)

@spec event(keyword()) :: UmaDb.V1.Event.t()

Builds an UmaDb.V1.Event struct from a keyword list.

Options

  • :type — (required) the event type, e.g. "OrderPlaced"
  • :tags — list of tag strings. Defaults to [].
  • :data — the serialized payload, a binary. Defaults to "".
  • :metadata — a map or keyword list of {key, value} string pairs, each converted into an UmaDb.V1.MetadataEntry. Defaults to [].
  • :uuid — identifier that enables idempotent conditional appends. Must be a valid UUID string; the server rejects anything else with a deserialization error. Defaults to "" (no identifier).

Raises ArgumentError if :type is missing or if unknown options are given.

Examples

iex> event = UmaDbClient.Builder.event(type: "OrderPlaced", tags: ["order:1"])
iex> event.event_type
"OrderPlaced"
iex> event.tags
["order:1"]

iex> event = UmaDbClient.Builder.event(type: "Foo", metadata: %{"user" => "alice"})
iex> event.metadata
[%UmaDb.V1.MetadataEntry{key: "user", value: "alice"}]

query(items)

@spec query([UmaDb.V1.QueryItem.t()]) :: UmaDb.V1.Query.t()

Builds a UmaDb.V1.Query from a list of UmaDb.V1.QueryItem structs.

query_item(types \\ [], tags \\ [])

@spec query_item([String.t()], [String.t()]) :: UmaDb.V1.QueryItem.t()

Builds a UmaDb.V1.QueryItem that matches events by type and/or tag.

tracking_info(source, position)

@spec tracking_info(String.t(), non_neg_integer()) :: UmaDb.V1.TrackingInfo.t()

Builds an UmaDb.V1.TrackingInfo to advance a named tracking cursor on append.