Slap.SlateDB.Iterator (slap_slatedb v0.2.0)

Copy Markdown View Source

A low-level iterator over a key range.

Most code should use the streams from Slap.SlateDB.scan/2, Slap.SlateDB.Snapshot.scan/2 and Slap.SlateDB.Transaction.scan/2 instead. Use this module when you need seek/2.

An iterator is not safe to share between processes that read from it at the same time. Calls are serialized, so the rows each process sees will interleave.

Summary

Functions

Returns up to max rows as {key, value} tuples. An iterator opened with with_versions: true returns {key, value, version} tuples. The version is nil for a transaction's uncommitted writes. Returns {:ok, []} when the iterator is done. :timeout applies to this batch fetch.

Moves the iterator forward to the first key that is at least key.

Types

t()

@opaque t()

Functions

next_batch(iterator, max \\ 256, opts \\ [])

@spec next_batch(t(), pos_integer(), keyword()) ::
  {:ok, [{binary(), binary()} | {binary(), binary(), non_neg_integer() | nil}]}
  | {:error, Slap.SlateDB.Error.t()}

Returns up to max rows as {key, value} tuples. An iterator opened with with_versions: true returns {key, value, version} tuples. The version is nil for a transaction's uncommitted writes. Returns {:ok, []} when the iterator is done. :timeout applies to this batch fetch.

seek(iterator, key, opts \\ [])

@spec seek(t(), binary(), keyword()) :: :ok | {:error, Slap.SlateDB.Error.t()}

Moves the iterator forward to the first key that is at least key.

The key must be inside the iterator's range and not before its current position. An iterator with order: :desc cannot seek; it returns an :invalid error.