View Source ActiveMemory.Operations (ActiveMemory v0.7.4)
The shared implementation of the table operations and store setup used by
ActiveMemory.Store and ActiveMemory.ActiveRepo.
Every function takes the table module explicitly and dispatches to that table's
configured adapter, applying the common validation, uuid handling, seeding and
before_init logic. This keeps the single-table Store and the multi-table
Repo sharing one implementation rather than duplicating it.
Link to this section Summary
Functions
Run the before_init methods for a store.
Delete the record provided.
Delete every record in table whose expires_at is at or before now
(milliseconds). Used by the Store/ActiveRepo sweep to reclaim memory; reads
already hide expired records, so this is only about freeing them.
Get one record matching an attributes map or a match query. An expired record
is treated as {:error, :not_found}.
Schedule the calling process's next expiry sweep when any of tables uses a
ttl, and do nothing when none of them do.
Evaluate seed_file and write its records to table.
Get all records matching an attributes map or a match query.
Delete every expired record from each of tables that uses a ttl.
Get one record matching the query, delete it, and return it. An expired record
is treated as {:error, :not_found}.
Write a record to table.
Link to this section Functions
Run the before_init methods for a store.
spec is :default, a single {method, args} tuple, or a list of such tuples.
module is the module the methods are defined on (the Store or Repo).
Delete the record provided.
Returns :ok for a struct matching table or for nil, and
{:error, :bad_schema} when the struct does not match table.
Delete every record in table whose expires_at is at or before now
(milliseconds). Used by the Store/ActiveRepo sweep to reclaim memory; reads
already hide expired records, so this is only about freeing them.
Get one record matching an attributes map or a match query. An expired record
is treated as {:error, :not_found}.
Schedule the calling process's next expiry sweep when any of tables uses a
ttl, and do nothing when none of them do.
The ttl lookup happens here, at runtime, rather than while a Store or
ActiveRepo compiles. Reading it at compile time would make every table a
compile time dependency of its store, which breaks tooling that compiles the
store's file without the table module loaded.
Evaluate seed_file and write its records to table.
A nil seed_file is a no-op. Returns {:ok, :seed_success} or
{:error, reason}.
Get all records matching an attributes map or a match query.
Returns {:error, :bad_select_query} for any other query shape.
Delete every expired record from each of tables that uses a ttl.
Tables without a ttl are skipped, so a repo holding a mix of both only pays
for the ones that expire.
Get one record matching the query, delete it, and return it. An expired record
is treated as {:error, :not_found}.
Write a record to table.
When the schema has a uuid field a value is generated if one is absent. When
the table has a ttl the record's expires_at is stamped from the current time.
Returns {:error, :bad_schema} when the struct does not match table.