Lethe (Lethe v0.2.1) View Source

Lethe

Lethe is a user-friendly query DSL for Mnesia. Currently, Lethe is focused on providing a sane API for reads, but I might add support for writes later.

The default options are:

  • Select all fields (Lethe.select_all)
  • Read lock (:read)
  • Select all values (Lethe.limit(:all))

Link to this section Summary

Types

The fields being returned by the query. These are the names of the fields, not Mnesia's numeric selectors or anything of the like.

The limit of values to return. If the limit is 0, it is converted to :all internally.

The type of table lock to use.

A boolean function that can be invoked in a matchspec. These functions are used for operating on the values being queried over, such as

The first tuple() is a {table(), result() | matchspec_any(), ...}

The name of the Mnesia table to query against

A result of an Mnesia transaction.

A failed transaction result. The inner term is the error returned by Mnesia.

A successful transaction result.

Link to this section Types

Specs

compiled_query() :: {table(), matchspec(), limit(), lock()}

Specs

field() :: atom()

The fields being returned by the query. These are the names of the fields, not Mnesia's numeric selectors or anything of the like.

Specs

field_or_guard() :: field() | matchspec_guard()

Specs

limit() :: :all | non_neg_integer()

The limit of values to return. If the limit is 0, it is converted to :all internally.

Specs

lock() :: :read | :write

The type of table lock to use.

Specs

matchspec() :: [matchspec_element()]

Specs

matchspec_all() :: :"$$"

Specs

matchspec_any() :: :_

Specs

matchspec_bool_func() ::
  :is_atom
  | :is_float
  | :is_integer
  | :is_list
  | :is_number
  | :is_pid
  | :is_port
  | :is_reference
  | :is_tuple
  | :is_map
  | :map_is_key
  | :is_binary
  | :is_function
  | :is_record
  | :and
  | :or
  | :not
  | :xor
  | :andalso
  | :orelse

A boolean function that can be invoked in a matchspec. These functions are used for operating on the values being queried over, such as:

  • "is X a pid?"
  • "is Y a key in X?"

Specs

matchspec_condition() :: matchspec_variable() | matchspec_guard()

Specs

matchspec_element() :: {tuple(), [matchspec_condition()], results()}

The first tuple() is a {table(), result() | matchspec_any(), ...}

Specs

Link to this type

matchspec_guard_func()

View Source

Specs

matchspec_guard_func() ::
  matchspec_bool_func()
  | :abs
  | :element
  | :hd
  | :length
  | :map_get
  | :map_size
  | :node
  | :round
  | :size
  | :bit_size
  | :tl
  | :trunc
  | :+
  | :-
  | :*
  | :div
  | :rem
  | :band
  | :bor
  | :bxor
  | :bnot
  | :bsl
  | :bsr
  | :>
  | :>=
  | :<
  | :"=<"
  | :"=:="
  | :==
  | :"=/="
  | :"/="
  | :self

Specs

matchspec_variable() :: result() | matchspec_any() | matchspec_all()

Specs

result() :: atom()

Specs

results() :: [result()]

Specs

table() :: atom()

The name of the Mnesia table to query against

Specs

transaction(res) :: transaction_success(res) | transaction_failure()

A result of an Mnesia transaction.

Specs

transaction_failure() :: {:error, {:transaction_aborted, term()}}

A failed transaction result. The inner term is the error returned by Mnesia.

Link to this type

transaction_success(res)

View Source

Specs

transaction_success(res) :: {:ok, res}

A successful transaction result.

Link to this section Functions