Sovite.Core.Lookup behaviour (sovite v0.2.0)

Copy Markdown View Source

The interface routing uses to read Sovite's database tables (Sovite.Core.Repo.Tables.*): a key goes in, a string value or nothing comes out.

A table is {module, handle}, where module implements lookup/2. Routing holds tables as {name, table} pairs, so a failure can name the table.

Telemetry

  • [:sovite, :tables, :lookup_error] - %{}, %{table, reason}: a table could not be read; the mail is deferred or answered with a temporary error.

Summary

Types

The result of a lookup: {:ok, value}, :error when the key is not in the table, or {:error, reason} when the table could not be read.

A table: a module and its handle.

Named tables, searched in order.

Functions

Tries each key in turn, in each table, and returns the first value found with the key that found it. A table that cannot be read stops the search and returns {:error, name}: a later table must not answer for a key the failing one might hold.

Types

result()

@type result() :: {:ok, String.t()} | :error | {:error, term()}

The result of a lookup: {:ok, value}, :error when the key is not in the table, or {:error, reason} when the table could not be read.

table()

@type table() :: {module(), term()}

A table: a module and its handle.

tables()

@type tables() :: [{String.t(), table()}]

Named tables, searched in order.

Callbacks

lookup(handle, key)

@callback lookup(handle :: term(), key :: String.t()) :: result()

Looks up key.

Functions

lookup(tables, keys)

@spec lookup(tables(), [String.t()]) ::
  {:ok, String.t(), String.t()} | :error | {:error, String.t()}

Tries each key in turn, in each table, and returns the first value found with the key that found it. A table that cannot be read stops the search and returns {:error, name}: a later table must not answer for a key the failing one might hold.