API Reference ActiveMemory v0.8.1

modules

Modules

The typed, attribute-queryable in memory store for ETS and Mnesia.

The ActiveRepo

An ActiveRepo manages multiple ActiveMemory.Tables from a single process. It is the multi-table counterpart to ActiveMemory.Store (which manages a single table), giving you one supervised entry point and a unified API over many tables.

An adapter for storing structs in ETS

An adapter for storing structs in Mnesia

Migrations will get run on app startup and are designed to modify :mnesia's schema.

Starts the ActiveMemory supervision tree, which runs the ActiveMemory.TableHeir process that preserves ETS tables across store crashes and restarts.

Finds database tables whose workload — read constantly, written rarely — makes them candidates for an ActiveMemory.Table.

Raised by one/1, one!/1, get_by/1 and get_by!/1 when a query intended to match a single record matches more than one.

Raised by the bang variants of the read functions (get!/1, get_by!/1, one!/1, reload!/1) when no record matches.

The shared implementation of the table operations and store setup used by ActiveMemory.Store and ActiveMemory.ActiveRepo.

The match/1 macro, for queries that need more than equality.

The Store

store-api

Store API

  • Store.all/1 Get all records stored, optionally ordered and paged (see Ordering and paging)
  • Store.count/1 Count the records stored, without reading them (see Counting)
  • Store.delete/1 Delete the record provided, matched in full (see Deleting a record)
  • Store.delete_all/0 Delete all records stored
  • Store.exists?/2 Whether any record matches an attributes search or match query
  • Store.get/1 Get the record with the given primary key, or {:error, :not_found}
  • Store.get!/1 Like get/1 but raises ActiveMemory.NotFoundError
  • Store.get_by/1 Get the single record matching an attributes search
  • Store.get_by!/1 Like get_by/1 but raises ActiveMemory.NotFoundError
  • Store.one/1 Get one record matching either an attributes search or match query. Raises ActiveMemory.MultipleResultsError when several match
  • Store.one!/1 Like one/1 but raises ActiveMemory.NotFoundError
  • Store.reload/1 Re-read a record from the table by its primary key
  • Store.reload!/1 Like reload/1 but raises ActiveMemory.NotFoundError
  • Store.select/2 Get all records matching either an attributes search or match query, optionally ordered and paged
  • Store.withdraw/1 Atomically get one record matching either an attributes search or match query, delete the record and return it — exactly one concurrent caller wins, making it safe for take-once workloads
  • Store.write/1 Write a record into the memory table, from a struct or an Ecto.Changeset. An invalid changeset is returned as {:error, changeset} with its action set to :insert, exactly like Ecto.Repo.insert/2

reading-a-single-record

Reading a single record

get/1 reads by primary key — the table's first field, which is what ETS and Mnesia key a record on. That is :uuid on a table using auto_generate_uuid: true, an Ecto schema's declared primary key, or simply the first field declared.

Define your table attributes and options.

Stable "owner of last resort" for the ETS tables created by ActiveMemory.Store.

mix-tasks

Mix Tasks

Reads your database's own table statistics through the application's Ecto repo and reports which tables have the high-read, low-write workload that makes them candidates for an ActiveMemory.Table.