CommBus.Storage.InMemory (CommBus v0.1.0)

Copy Markdown View Source

Lightweight ETS-backed storage adapter implementing both CommBus storage behaviours.

This adapter is useful for tests, prototyping, and consumers that do not yet have a database wired up. Tables are created on demand and names can be customized via the :entries_table and :conversations_table application env keys.

Summary

Functions

Removes an entry from the ETS table by ID.

Looks up a single entry by ID in the ETS table.

Lists all entries from the ETS table, applying optional keyword filters for :enabled, :mode, and :keywords.

Looks up a conversation by ID in the ETS table.

Stores a conversation in the ETS table, auto-generating an ID if not present.

Stores an entry in the ETS table, auto-generating an ID if not present.

Updates an existing conversation in the ETS table, merging the given updates into the existing struct.

Functions

delete_entry(id)

Removes an entry from the ETS table by ID.

Parameters

  • id — The entry identifier.

Returns

:ok.

get_entry(id)

Looks up a single entry by ID in the ETS table.

Parameters

  • id — The entry identifier.

Returns

{:ok, %CommBus.Entry{}} if found, or {:error, :not_found}.

list_entries(opts)

Lists all entries from the ETS table, applying optional keyword filters for :enabled, :mode, and :keywords.

Parameters

  • opts — Keyword filters.

Returns

{:ok, [%CommBus.Entry{}]}.

load_conversation(id)

Looks up a conversation by ID in the ETS table.

Parameters

  • id — The conversation identifier.

Returns

{:ok, %CommBus.Conversation{}} if found, or {:error, :not_found}.

store_conversation(conversation)

Stores a conversation in the ETS table, auto-generating an ID if not present.

Parameters

  • conversation — A %CommBus.Conversation{} struct.

Returns

{:ok, %CommBus.Conversation{}} with the (possibly auto-generated) ID.

store_entry(entry)

Stores an entry in the ETS table, auto-generating an ID if not present.

Parameters

  • entry — A %CommBus.Entry{} struct.

Returns

{:ok, %CommBus.Entry{}} with the (possibly auto-generated) ID.

update_conversation(id, updates)

Updates an existing conversation in the ETS table, merging the given updates into the existing struct.

Parameters

  • id — The conversation identifier.
  • updates — A map of fields to update.

Returns

{:ok, %CommBus.Conversation{}} on success, or {:error, :not_found}.