Bedrock.KeySelector (bedrock v0.6.0)
View SourceA KeySelector describes a key in the database that can be resolved to an actual key at runtime.
KeySelectors leverage the lexicographically ordered nature of keys to find keys based on their positional relationships to other keys, without needing to know exact key values.
Examples
iex> KeySelector.first_greater_or_equal("user:")
%KeySelector{key: "user:", or_equal: true, offset: 0}
iex> KeySelector.first_greater_than("data") |> KeySelector.add(5)
%KeySelector{key: "data", or_equal: false, offset: 6}
Summary
Functions
Adds an offset to a KeySelector, moving the resolution point forward (positive) or backward (negative) by the specified number of keys.
Creates a KeySelector that resolves to the lexicographically smallest key greater than or equal to the given key.
Creates a KeySelector that resolves to the lexicographically smallest key strictly greater than the given key.
Creates a KeySelector that resolves to the lexicographically largest key less than or equal to the given key.
Creates a KeySelector that resolves to the lexicographically largest key strictly less than the given key.
Returns true if the KeySelector has a negative offset, meaning it will resolve to a key that comes before the reference position.
Returns true if the KeySelector has a positive offset, meaning it will resolve to a key that comes after the reference position.
Subtracts an offset from a KeySelector, moving the resolution point backward (positive) or forward (negative) by the specified number of keys.
Converts a KeySelector to a human-readable string representation.
Returns true if the KeySelector has a zero offset, meaning it resolves to a key based only on the base key and or_equal flag.
Types
Functions
Adds an offset to a KeySelector, moving the resolution point forward (positive) or backward (negative) by the specified number of keys.
Examples
iex> KeySelector.first_greater_or_equal("a") |> KeySelector.add(3)
%KeySelector{key: "a", or_equal: true, offset: 3}
iex> KeySelector.first_greater_than("z") |> KeySelector.add(-2)
%KeySelector{key: "z", or_equal: false, offset: -1}
Creates a KeySelector that resolves to the lexicographically smallest key greater than or equal to the given key.
Creates a KeySelector that resolves to the lexicographically smallest key strictly greater than the given key.
Creates a KeySelector that resolves to the lexicographically largest key less than or equal to the given key.
Creates a KeySelector that resolves to the lexicographically largest key strictly less than the given key.
Returns true if the KeySelector has a negative offset, meaning it will resolve to a key that comes before the reference position.
Returns true if the KeySelector has a positive offset, meaning it will resolve to a key that comes after the reference position.
Subtracts an offset from a KeySelector, moving the resolution point backward (positive) or forward (negative) by the specified number of keys.
Examples
iex> KeySelector.first_greater_or_equal("m") |> KeySelector.subtract(2)
%KeySelector{key: "m", or_equal: true, offset: -2}
Converts a KeySelector to a human-readable string representation.
Examples
iex> KeySelector.first_greater_or_equal("user:") |> KeySelector.to_string()
"first_greater_or_equal("user:")"
iex> KeySelector.first_greater_than("data") |> KeySelector.add(3) |> KeySelector.to_string()
"first_greater_than("data") + 3"
Returns true if the KeySelector has a zero offset, meaning it resolves to a key based only on the base key and or_equal flag.