MingaAgent.EventLog.Store (Minga v0.1.0)

Copy Markdown View Source

SQLite storage backend for durable agent session events.

Summary

Functions

Closes the database connection.

Returns the total number of agent events.

Deletes events older than the given wall-clock time.

Returns all events for a session with id greater than the cursor, ordered by id.

Inserts an append-only event record.

Runs a SQLite integrity check.

Returns the latest event id for a session, or 0 when it has no events.

Opens or creates the agent event database.

Opens an in-memory database for tests.

Types

db()

@type db() :: Exqlite.Sqlite3.db()

Functions

close(db)

@spec close(db()) :: :ok | {:error, term()}

Closes the database connection.

count(db)

@spec count(db()) :: {:ok, non_neg_integer()} | {:error, term()}

Returns the total number of agent events.

delete_before(db, cutoff)

@spec delete_before(db(), DateTime.t()) :: {:ok, non_neg_integer()} | {:error, term()}

Deletes events older than the given wall-clock time.

events_after(db, session_id, last_id, limit \\ 1000)

@spec events_after(db(), String.t(), non_neg_integer(), pos_integer()) ::
  {:ok, [MingaAgent.EventLog.EventRecord.t()]} | {:error, term()}

Returns all events for a session with id greater than the cursor, ordered by id.

insert(db, record)

@spec insert(db(), MingaAgent.EventLog.EventRecord.t()) ::
  {:ok, pos_integer()} | {:error, term()}

Inserts an append-only event record.

integrity_check(db, mode \\ :quick)

@spec integrity_check(db(), :full | :quick) ::
  {:ok, :healthy} | {:error, [String.t()]}

Runs a SQLite integrity check.

latest_id(db, session_id)

@spec latest_id(db(), String.t()) :: {:ok, non_neg_integer()} | {:error, term()}

Returns the latest event id for a session, or 0 when it has no events.

open(db_path)

@spec open(String.t()) :: {:ok, db()} | {:error, term()}

Opens or creates the agent event database.

open_memory()

@spec open_memory() :: {:ok, db()} | {:error, term()}

Opens an in-memory database for tests.