Bedrock.Keyspace (bedrock v0.6.0)

View Source

Elixir implementation of FoundationDB Subspace functionality.

A Keyspace represents a well-defined region of keyspace in a FoundationDB database. It provides a convenient way to use FoundationDB tuples to define namespaces for different categories of data. The namespace is specified by a prefix tuple which is prepended to all tuples packed by the keyspace. When unpacking a key with the keyspace, the prefix tuple will be removed from the result.

Based on the pattern from other FoundationDB language bindings (Go, Rust, C++).

Summary

Functions

Add an item to the keyspace, creating a new keyspace. The item will be packed as a single-element tuple and appended.

Create a keyspace that contains all keys in the database.

Check if a key belongs to this keyspace (starts with the prefix).

Create a new keyspace from raw bytes prefix.

Create a nested keyspace by extending this keyspace with the given binary, or term if the keyspace supports key encoding.

Convert the keyspace to a string representation for debugging.

Types

keyspace_opts()

@type keyspace_opts() :: [key_encoding: module(), value_encoding: module()]

t()

@type t() :: %Bedrock.Keyspace{
  key_encoding: module(),
  prefix: binary(),
  value_encoding: module()
}

Functions

add(keyspace, item)

@spec add(t(), term()) :: t()

Add an item to the keyspace, creating a new keyspace. The item will be packed as a single-element tuple and appended.

all()

@spec all() :: t()

Create a keyspace that contains all keys in the database.

contains?(keyspace, key)

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

Check if a key belongs to this keyspace (starts with the prefix).

get_range_from_repo(keyspace, repo, opts \\ [])

@spec get_range_from_repo(t(), repo :: module(), opts :: keyword()) :: Enumerable.t()

new(prefix, opts \\ [])

@spec new(
  prefix :: binary(),
  opts :: [key_encoding: module(), value_encoding: module()]
) :: t()

Create a new keyspace from raw bytes prefix.

pack(arg1, key)

@spec pack(t(), binary()) :: binary()
@spec pack(t(), any()) :: binary()

partition(keyspace, name, opts \\ [])

@spec partition(t(), binary(), keyspace_opts()) :: t()
@spec partition(t(), term(), keyspace_opts()) :: t()

Create a nested keyspace by extending this keyspace with the given binary, or term if the keyspace supports key encoding.

prefix(keyspace)

@spec prefix(t()) :: binary()

to_string(keyspace)

@spec to_string(t()) :: String.t()

Convert the keyspace to a string representation for debugging.

unpack(keyspace, key)

@spec unpack(t(), key :: binary()) :: binary()
@spec unpack(t(), key :: binary()) :: term()