View Source CubDB.Snapshot (cubdb v2.0.2)

The CubDB.Snapshot module contains functions to read from snapshots obtained with CubDB.with_snapshot/2 or CubDB.snapshot/2.

The functions in this module mirror the ones with the same name in the CubDB module, but work on snapshots instead of on the live database.

Link to this section Summary

Functions

Creates a backup of the snapshot into the target directory path

Fetches the value for the given key from the snapshot, or returns :error if key is not present.

Gets the value associated to key from the snapshot.

Gets multiple entries corresponding by the given keys from the snapshot all at once, atomically.

Returns whether an entry with the given key exists in the snapshot.

Selects a range of entries from the snapshot, returning a lazy stream.

Returns the number of entries present in the snapshot.

Link to this section Types

@type t() :: snapshot()

Link to this section Functions

Link to this function

back_up(snapshot, target_path)

View Source
@spec back_up(t(), Path.t()) :: :ok | {:error, term()}

Creates a backup of the snapshot into the target directory path

It works the same as CubDB.back_up/2, but works on a snapshot instead of the live database.

@spec fetch(t(), CubDB.key()) :: {:ok, CubDB.value()} | :error

Fetches the value for the given key from the snapshot, or returns :error if key is not present.

If the snapshot contains an entry with the given key and value value, it returns {:ok, value}. If key is not found, it returns :error.

It works the same as CubDB.fetch/2, but reads from a snapshot instead of the live database.

Link to this function

get(snapshot, key, default \\ nil)

View Source
@spec get(t(), CubDB.key(), CubDB.value()) :: CubDB.value()

Gets the value associated to key from the snapshot.

If no value is associated with key, default is returned (which is nil, unless specified otherwise).

It works the same as CubDB.get/3, but reads from a snapshot instead of the live database.

Link to this function

get_multi(snapshot, keys)

View Source
@spec get_multi(t(), [CubDB.key()]) :: %{required(CubDB.key()) => CubDB.value()}

Gets multiple entries corresponding by the given keys from the snapshot all at once, atomically.

It works the same as CubDB.get_multi/2, but reads from a snapshot instead of the live database.

@spec has_key?(t(), CubDB.key()) :: boolean()

Returns whether an entry with the given key exists in the snapshot.

It works the same as CubDB.has_key?/2, but reads from a snapshot instead of the live database.

Link to this function

select(snap, options \\ [])

View Source

Selects a range of entries from the snapshot, returning a lazy stream.

The lazy stream should be evaluated while the snapshot is still valid, or a RuntimeError will be raised.

It works the same and accepts the same options as CubDB.select/2, but reads from a snapshot instead of the live database.

@spec size(t()) :: non_neg_integer()

Returns the number of entries present in the snapshot.

It works the same as CubDB.size/1, but works on a snapshot instead of the live database.