View Source FDB.Database (fdb v7.1.5-0)

This module provides functions to create and configure database and functions to do transactions on database.

Link to this section Summary

Functions

Creates a new database. If the cluster_file_path is not set then default cluster file will be used.

Refer FDB.Transaction.get_range/3. The only difference is the consistency guarantee. This function uses multiple transactions to fetch the data. This is advantageous if you want to fetch large amount of data and are ok with the fact that the data might change when doing the iteration.

Changes the defaults options associated with the database.

Refer FDB.Option for the list of options. Any option that starts with database_option_ is allowed.

Refer FDB.Option for the list of options. Any option that starts with database_option_ is allowed.

The given callback will be called with a FDB.Transaction.t/0.

Link to this section Types

Specs

t() :: %FDB.Database{coder: term(), resource: term()}

Link to this section Functions

Link to this function

create(cluster_file_path \\ nil, defaults \\ %{})

View Source

Specs

create(String.t() | nil, map()) :: t()

Creates a new database. If the cluster_file_path is not set then default cluster file will be used.

Link to this function

get_range_stream(database, key_range, options \\ %{})

View Source

Specs

get_range_stream(t(), FDB.KeySelectorRange.t(), map()) :: Enumerable.t()

Refer FDB.Transaction.get_range/3. The only difference is the consistency guarantee. This function uses multiple transactions to fetch the data. This is advantageous if you want to fetch large amount of data and are ok with the fact that the data might change when doing the iteration.

Link to this function

set_defaults(db, defaults)

View Source

Specs

set_defaults(t(), map()) :: t()

Changes the defaults options associated with the database.

This doesn't create a new database resource, the same database resource is shared. This is the recommended way if one needs to use multiple coders.

db = FDB.Database.create(cluster_file_path)
user_db = FDB.Database.set_defaults(db, %{coder: user_coder})
comments_db = FDB.Database.set_defaults(db, %{coder: comment_coder})
Link to this function

set_option(database, option)

View Source

Specs

set_option(t(), FDB.Option.key()) :: :ok

Refer FDB.Option for the list of options. Any option that starts with database_option_ is allowed.

Link to this function

set_option(database, option, value)

View Source

Specs

set_option(t(), FDB.Option.key(), FDB.Option.value()) :: :ok

Refer FDB.Option for the list of options. Any option that starts with database_option_ is allowed.

Link to this function

transact(database, callback)

View Source

Specs

transact(t(), (FDB.Transaction.t() -> any())) :: any()

The given callback will be called with a FDB.Transaction.t/0.

The transaction is automatically committed after the callback returns. The value returned by the callback is retuned. In case any exception is raised inside the callback or in the commit function call, the transaction will be retried if the error is retriable. It also implements an exponential backoff strategy to avoid swamping the database cluster with excessive retries when there is a high level of conflict between transactions.

Avoid doing any IO or any action that will cause side effect inside the callback, as the callback might get called multiple times in case of errors.

Various options like FDB.Option.transaction_option_max_retry_delay/0, FDB.Option.transaction_option_timeout/0, FDB.Option.transaction_option_retry_limit/0 etc which control the retry behaviour can be configured using FDB.Transaction.set_option/3