Slap.SlateDB.Transaction (slap_slatedb v0.2.0)

Copy Markdown View Source

A read-write transaction.

Start one with Slap.SlateDB.begin/2 or, more simply, Slap.SlateDB.transaction/3. Reads see the database as of the start of the transaction plus the transaction's own writes. Writes stay in memory until commit/2.

A transaction belongs to the process that uses it. Do not use it from more than one process at the same time.

Summary

Functions

Commits the transaction.

Adds a delete to the transaction.

Reads key, including this transaction's uncommitted writes. Takes the options of Slap.SlateDB.get/3.

Reads key with its metadata, like Slap.SlateDB.get_key_value/3, including this transaction's uncommitted writes. Their :seq is nil until commit.

Opens an iterator over the transaction's rows. See Slap.SlateDB.iterator/2.

Adds a merge operand to the transaction. The database must be opened with a :merge_operator; see Slap.SlateDB.merge/4. Takes the :ttl option of put/4.

Adds a put to the transaction.

Throws away the transaction's writes. Rolling back twice is allowed.

Scans rows, including this transaction's uncommitted writes. With with_versions: true, those writes have a nil version. See Slap.SlateDB.scan/2.

Types

t()

@opaque t()

Functions

commit(transaction, opts \\ [])

@spec commit(t(), keyword()) ::
  {:ok, non_neg_integer() | nil} | {:error, Slap.SlateDB.Error.t()}

Commits the transaction.

Returns {:ok, seq} with the commit's sequence number, or {:ok, nil} if the transaction made no writes. Returns {:error, %Slap.SlateDB.Error{kind: :conflict}} if the transaction conflicts with another one that committed first.

Options

  • :await_durable - when true, returns only after the writes are durable in object storage. Defaults to false.
  • :timeout - see Slap.SlateDB.get/3.

delete(transaction, key)

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

Adds a delete to the transaction.

get(tx, key, opts \\ [])

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

Reads key, including this transaction's uncommitted writes. Takes the options of Slap.SlateDB.get/3.

get_key_value(tx, key, opts \\ [])

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

Reads key with its metadata, like Slap.SlateDB.get_key_value/3, including this transaction's uncommitted writes. Their :seq is nil until commit.

iterator(tx, opts \\ [])

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

Opens an iterator over the transaction's rows. See Slap.SlateDB.iterator/2.

merge(transaction, key, operand, opts \\ [])

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

Adds a merge operand to the transaction. The database must be opened with a :merge_operator; see Slap.SlateDB.merge/4. Takes the :ttl option of put/4.

put(transaction, key, value, opts \\ [])

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

Adds a put to the transaction.

Options

  • :ttl - time to live in milliseconds. By default, the database's default_ttl_millis setting applies.

rollback(transaction)

@spec rollback(t()) :: :ok

Throws away the transaction's writes. Rolling back twice is allowed.

scan(tx, opts \\ [])

@spec scan(t(), keyword()) :: Enumerable.t()

Scans rows, including this transaction's uncommitted writes. With with_versions: true, those writes have a nil version. See Slap.SlateDB.scan/2.