PhoenixAI.Store.Adapters.Ecto (PhoenixAI.Store v0.1.0)

Copy Markdown View Source

Ecto/Postgres adapter for PhoenixAI.Store.Adapter.

All callbacks receive an opts keyword list containing a :repo key pointing to the Ecto.Repo module to use for queries.

This module is only compiled when Ecto is available as a dependency.

Summary

Functions

Inserts a message row into the database. Returns {:error, :not_found} if the conversation does not exist.

Checks whether a conversation exists in the database using Repo.exists?/1.

Counts conversation rows matching the given filters using a database COUNT query.

Counts event rows matching the given filters using a database COUNT query.

Counts fact rows for a user using a database COUNT query.

Deletes a conversation row from the database. Returns {:error, :not_found} if absent.

Deletes all fact rows matching {user_id, key} from the database.

Deletes all profile rows for a user from the database.

Queries all cost records for a conversation from the database, ordered by recorded_at ascending.

Queries all facts for a user from the database, ordered by inserted_at ascending.

Queries all messages for a conversation from the database, ordered by inserted_at ascending.

Queries conversations from the database with optional filters, ordered by inserted_at descending.

Queries a paginated, filtered list of events from the database with an opaque cursor for the next page.

Loads a conversation by ID from the database, preloading messages ordered by inserted_at.

Loads a user profile from the database. Returns {:error, :not_found} if absent.

Inserts an event row into the database. The event log is append-only — no updates or deletes.

Inserts or updates a conversation row in the database via the configured Repo.

Inserts a cost record row into the database. Records are immutable once written.

Upserts a fact row in the database using ON CONFLICT DO UPDATE on {user_id, key}.

Upserts a profile row in the database using ON CONFLICT DO UPDATE on user_id.

Sums token_count for all messages in a conversation using a database SUM aggregate.

Sums total_cost across cost records matching the given filters using a database SUM aggregate.

Sums token_count across all messages in all conversations belonging to a user via a database join.

Functions

add_message(conversation_id, message, opts)

Inserts a message row into the database. Returns {:error, :not_found} if the conversation does not exist.

conversation_exists?(id, opts)

Checks whether a conversation exists in the database using Repo.exists?/1.

count_conversations(filters, opts)

Counts conversation rows matching the given filters using a database COUNT query.

count_events(filters, opts)

Counts event rows matching the given filters using a database COUNT query.

count_facts(user_id, opts)

Counts fact rows for a user using a database COUNT query.

delete_conversation(id, opts)

Deletes a conversation row from the database. Returns {:error, :not_found} if absent.

delete_fact(user_id, key, opts)

Deletes all fact rows matching {user_id, key} from the database.

delete_profile(user_id, opts)

Deletes all profile rows for a user from the database.

get_cost_records(conversation_id, opts)

Queries all cost records for a conversation from the database, ordered by recorded_at ascending.

get_facts(user_id, opts)

Queries all facts for a user from the database, ordered by inserted_at ascending.

get_messages(conversation_id, opts)

Queries all messages for a conversation from the database, ordered by inserted_at ascending.

list_conversations(filters, opts)

Queries conversations from the database with optional filters, ordered by inserted_at descending.

list_events(filters, opts)

Queries a paginated, filtered list of events from the database with an opaque cursor for the next page.

load_conversation(id, opts)

Loads a conversation by ID from the database, preloading messages ordered by inserted_at.

load_profile(user_id, opts)

Loads a user profile from the database. Returns {:error, :not_found} if absent.

log_event(event, opts)

Inserts an event row into the database. The event log is append-only — no updates or deletes.

save_conversation(conversation, opts)

Inserts or updates a conversation row in the database via the configured Repo.

save_cost_record(record, opts)

Inserts a cost record row into the database. Records are immutable once written.

save_fact(fact, opts)

Upserts a fact row in the database using ON CONFLICT DO UPDATE on {user_id, key}.

save_profile(profile, opts)

Upserts a profile row in the database using ON CONFLICT DO UPDATE on user_id.

sum_conversation_tokens(conversation_id, opts)

Sums token_count for all messages in a conversation using a database SUM aggregate.

sum_cost(filters, opts)

Sums total_cost across cost records matching the given filters using a database SUM aggregate.

sum_user_tokens(user_id, opts)

Sums token_count across all messages in all conversations belonging to a user via a database join.