Concord.KV.Selector (Concord v2.0.0)

Copy Markdown View Source

Unified selector type for addressing keys in Concord.

Selectors are used across the KV, Transaction, and Sync APIs to specify which keys an operation targets. Three forms are supported:

  • {:key, binary()} — Exactly one key
  • {:prefix, binary()} — All keys starting with the given prefix
  • {:range, start :: binary(), end_exclusive :: binary()} — All keys in the half-open interval [start, end)

{:prefix, p} is sugar for {:range, p, p <> <<0xFF, 0xFF, ...>>}.

Summary

Functions

Checks if a key matches the given selector.

Returns the upper bound binary for a prefix scan.

Validates a selector value.

Types

t()

@type t() ::
  {:key, binary()}
  | {:prefix, binary()}
  | {:range, start :: binary(), end_exclusive :: binary()}

Functions

matches?(arg, key)

@spec matches?(t(), binary()) :: boolean()

Checks if a key matches the given selector.

prefix_end(prefix)

@spec prefix_end(binary()) :: binary()

Returns the upper bound binary for a prefix scan.

For a prefix p, the upper bound is p with each trailing byte incremented, effectively matching all keys that start with p.

validate(arg1)

@spec validate(term()) :: :ok | {:error, atom()}

Validates a selector value.

Returns :ok if valid, {:error, reason} otherwise.