Fact.Seam.Storage behaviour (Fact v0.2.1)

View Source

Behaviour defining the storage configuration for a Fact database.

This Fact.Seam implementation specifies the paths used by the system for storing events, indices, ledgers, and locks. Implementations of this behaviour allow different storage layouts, file structures, or storage backends to be plugged in.

Responsibilities

  • path/2 – Returns the root path of the database.
  • records_path/3 – Returns the path where event records are stored, or the path to a specific record.
  • indices_path/2 – Returns the path where index files are stored.
  • ledger_path/2 – Returns the path for the event ledger file(s).
  • locks_path/2 – Returns the path for lock files used for database concurrency.

Each function receives a configured instance (t()) and optional keyword arguments, and should return either a valid Path.t() or an error tuple.

This allows the Fact system to operate on different storage strategies without changing the core database or event logic.

Summary

Callbacks

A callback function that gets the base path to the directory where all index files are stored.

A callback function that initializes the directory structure used for records, indexes, and any other files used by the database.

A callback function that gets the path to the directory containing the ledger file.

A callback function that gets the path to the directory containing the lock files.

A callback function that gets the path to configured root directory for the database.

A callback function that gets the directory containing all records, or the path to a specific record.

Types

t()

(since 0.1.0)
@type t() :: struct()

Callbacks

default_options()

(since 0.1.0)
@callback default_options() :: map()

family()

(since 0.1.0)
@callback family() :: atom()

id()

(since 0.1.0)
@callback id() :: {atom(), non_neg_integer()}

indices_path(t, opts)

(since 0.1.0)
@callback indices_path(t(), opts :: keyword()) :: Path.t() | {:error, term()}

A callback function that gets the base path to the directory where all index files are stored.

init(map)

(since 0.1.0)
@callback init(map()) :: struct() | {:error, term()}

initialize_storage(t, opts)

(since 0.2.0)
@callback initialize_storage(t(), opts :: keyword()) :: {:ok, Path.t()} | {:error, term()}

A callback function that initializes the directory structure used for records, indexes, and any other files used by the database.

ledger_path(t, opts)

(since 0.1.0)
@callback ledger_path(t(), opts :: keyword()) :: Path.t() | {:error, term()}

A callback function that gets the path to the directory containing the ledger file.

locks_path(t, opts)

(since 0.1.0)
@callback locks_path(t(), opts :: keyword()) :: Path.t() | {:error, term()}

A callback function that gets the path to the directory containing the lock files.

normalize_options(map)

(since 0.1.0)
@callback normalize_options(map()) :: {:ok, map()} | {:error, term()}

option_specs()

(since 0.1.0)
@callback option_specs() :: %{required(atom()) => map()}

path(t, opts)

(since 0.1.0)
@callback path(t(), opts :: keyword()) :: Path.t() | {:error, term()}

A callback function that gets the path to configured root directory for the database.

prepare_options(map)

(since 0.1.0)
@callback prepare_options(map()) :: map()

records_path(t, record_id, opts)

(since 0.2.0)
@callback records_path(t(), record_id :: String.t(), opts :: keyword()) ::
  Path.t() | {:error, term()}

A callback function that gets the directory containing all records, or the path to a specific record.

version()

(since 0.1.0)
@callback version() :: non_neg_integer()