Skip to main content

Class: DatabaseAdapter

An abstract class representing a database adapter for managing various entities like accounts, memories, actors, goals, and rooms.

Hierarchy

Constructors

constructor

new DatabaseAdapter(): DatabaseAdapter

Returns

DatabaseAdapter

Methods

addParticipant

addParticipant(user_id, room_id): Promise<boolean>

Adds a user as a participant to a specific room.

Parameters

NameTypeDescription
user_id`${string}-${string}-${string}-${string}-${string}`The UUID of the user to add as a participant.
room_id`${string}-${string}-${string}-${string}-${string}`The UUID of the room to which the user will be added.

Returns

Promise<boolean>

A Promise that resolves to a boolean indicating success or failure.


countMemories

countMemories(room_id, unique?, tableName?): Promise<number>

Counts the number of memories in a specific room.

Parameters

NameTypeDescription
room_id`${string}-${string}-${string}-${string}-${string}`The UUID of the room for which to count memories.
unique?booleanSpecifies whether to count only unique memories.
tableName?stringOptional table name to count memories from.

Returns

Promise<number>

A Promise that resolves to the number of memories.


createAccount

createAccount(account): Promise<boolean>

Creates a new account in the database.

Parameters

NameTypeDescription
accountAccountThe account object to create.

Returns

Promise<boolean>

A Promise that resolves when the account creation is complete.


createGoal

createGoal(goal): Promise<void>

Creates a new goal in the database.

Parameters

NameTypeDescription
goalGoalThe goal object to create.

Returns

Promise<void>

A Promise that resolves when the goal has been created.


createMemory

createMemory(memory, tableName, unique?): Promise<void>

Creates a new memory in the database.

Parameters

NameTypeDescription
memoryMemoryThe memory object to create.
tableNamestringThe table where the memory should be stored.
unique?booleanIndicates if the memory should be unique.

Returns

Promise<void>

A Promise that resolves when the memory has been created.


createRelationship

createRelationship(params): Promise<boolean>

Creates a new relationship between two users.

Parameters

NameTypeDescription
paramsObjectAn object containing the UUIDs of the two users (userA and userB).
params.userA`${string}-${string}-${string}-${string}-${string}`-
params.userB`${string}-${string}-${string}-${string}-${string}`-

Returns

Promise<boolean>

A Promise that resolves to a boolean indicating success or failure of the creation.


createRoom

createRoom(room_id?): Promise<`${string}-${string}-${string}-${string}-${string}`>

Creates a new room with an optional specified ID.

Parameters

NameTypeDescription
room_id?`${string}-${string}-${string}-${string}-${string}`Optional UUID to assign to the new room.

Returns

Promise<`${string}-${string}-${string}-${string}-${string}`>

A Promise that resolves to the UUID of the created room.


getAccountById

getAccountById(user_id): Promise<null | Account>

Retrieves an account by its ID.

Parameters

NameTypeDescription
user_id`${string}-${string}-${string}-${string}-${string}`The UUID of the user account to retrieve.

Returns

Promise<null | Account>

A Promise that resolves to the Account object or null if not found.


getActorDetails

getActorDetails(params): Promise<Actor[]>

Retrieves details of actors in a given room.

Parameters

NameTypeDescription
paramsObjectAn object containing the room_id to search for actors.
params.room_id`${string}-${string}-${string}-${string}-${string}`-

Returns

Promise<Actor[]>

A Promise that resolves to an array of Actor objects.


getCachedEmbeddings

getCachedEmbeddings(params): Promise<{ embedding: number[] ; levenshtein_score: number }[]>

Retrieves cached embeddings based on the specified query parameters.

Parameters

NameTypeDescription
paramsObjectAn object containing parameters for the embedding retrieval.
params.query_field_namestring-
params.query_field_sub_namestring-
params.query_inputstring-
params.query_match_countnumber-
params.query_table_namestring-
params.query_thresholdnumber-

Returns

Promise<{ embedding: number[] ; levenshtein_score: number }[]>

A Promise that resolves to an array of objects containing embeddings and levenshtein scores.


getGoals

getGoals(params): Promise<Goal[]>

Retrieves goals based on specified parameters.

Parameters

NameTypeDescription
paramsObjectAn object containing parameters for goal retrieval.
params.count?number-
params.onlyInProgress?boolean-
params.room_id`${string}-${string}-${string}-${string}-${string}`-
params.user_id?null | `${string}-${string}-${string}-${string}-${string}`-

Returns

Promise<Goal[]>

A Promise that resolves to an array of Goal objects.


getMemories

getMemories(params): Promise<Memory[]>

Retrieves memories based on the specified parameters.

Parameters

NameTypeDescription
paramsObjectAn object containing parameters for the memory retrieval.
params.count?number-
params.room_id`${string}-${string}-${string}-${string}-${string}`-
params.tableNamestring-
params.unique?boolean-

Returns

Promise<Memory[]>

A Promise that resolves to an array of Memory objects.


getParticipantsForAccount

getParticipantsForAccount(user_id): Promise<Participant[]>

Retrieves participants associated with a specific account.

Parameters

NameTypeDescription
user_id`${string}-${string}-${string}-${string}-${string}`The UUID of the account.

Returns

Promise<Participant[]>

A Promise that resolves to an array of Participant objects.

getParticipantsForAccount(user_id): Promise<Participant[]>

Retrieves participants associated with a specific account.

Parameters

NameTypeDescription
user_id`${string}-${string}-${string}-${string}-${string}`The UUID of the account.

Returns

Promise<Participant[]>

A Promise that resolves to an array of Participant objects.


getParticipantsForRoom

getParticipantsForRoom(room_id): Promise<`${string}-${string}-${string}-${string}-${string}`[]>

Retrieves participants for a specific room.

Parameters

NameTypeDescription
room_id`${string}-${string}-${string}-${string}-${string}`The UUID of the room for which to retrieve participants.

Returns

Promise<`${string}-${string}-${string}-${string}-${string}`[]>

A Promise that resolves to an array of UUIDs representing the participants.


getRelationship

getRelationship(params): Promise<null | Relationship>

Retrieves a relationship between two users if it exists.

Parameters

NameTypeDescription
paramsObjectAn object containing the UUIDs of the two users (userA and userB).
params.userA`${string}-${string}-${string}-${string}-${string}`-
params.userB`${string}-${string}-${string}-${string}-${string}`-

Returns

Promise<null | Relationship>

A Promise that resolves to the Relationship object or null if not found.


getRelationships

getRelationships(params): Promise<Relationship[]>

Retrieves all relationships for a specific user.

Parameters

NameTypeDescription
paramsObjectAn object containing the UUID of the user.
params.user_id`${string}-${string}-${string}-${string}-${string}`-

Returns

Promise<Relationship[]>

A Promise that resolves to an array of Relationship objects.


getRoom

getRoom(room_id): Promise<null | `${string}-${string}-${string}-${string}-${string}`>

Retrieves the room ID for a given room, if it exists.

Parameters

NameTypeDescription
room_id`${string}-${string}-${string}-${string}-${string}`The UUID of the room to retrieve.

Returns

Promise<null | `${string}-${string}-${string}-${string}-${string}`>

A Promise that resolves to the room ID or null if not found.


getRoomsForParticipant

getRoomsForParticipant(user_id): Promise<`${string}-${string}-${string}-${string}-${string}`[]>

Retrieves room IDs for which a specific user is a participant.

Parameters

NameTypeDescription
user_id`${string}-${string}-${string}-${string}-${string}`The UUID of the user.

Returns

Promise<`${string}-${string}-${string}-${string}-${string}`[]>

A Promise that resolves to an array of room IDs.


getRoomsForParticipants

getRoomsForParticipants(userIds): Promise<`${string}-${string}-${string}-${string}-${string}`[]>

Retrieves room IDs for which specific users are participants.

Parameters

NameTypeDescription
userIds`${string}-${string}-${string}-${string}-${string}`[]An array of UUIDs of the users.

Returns

Promise<`${string}-${string}-${string}-${string}-${string}`[]>

A Promise that resolves to an array of room IDs.


log

log(params): Promise<void>

Logs an event or action with the specified details.

Parameters

NameTypeDescription
paramsObjectAn object containing parameters for the log entry.
params.bodyObject-
params.room_id`${string}-${string}-${string}-${string}-${string}`-
params.typestring-
params.user_id`${string}-${string}-${string}-${string}-${string}`-

Returns

Promise<void>

A Promise that resolves when the log entry has been saved.


removeAllGoals

removeAllGoals(room_id): Promise<void>

Removes all goals associated with a specific room.

Parameters

NameTypeDescription
room_id`${string}-${string}-${string}-${string}-${string}`The UUID of the room whose goals should be removed.

Returns

Promise<void>

A Promise that resolves when all goals have been removed.


removeAllMemories

removeAllMemories(room_id, tableName): Promise<void>

Removes all memories associated with a specific room.

Parameters

NameTypeDescription
room_id`${string}-${string}-${string}-${string}-${string}`The UUID of the room whose memories should be removed.
tableNamestringThe table from which the memories should be removed.

Returns

Promise<void>

A Promise that resolves when all memories have been removed.


removeGoal

removeGoal(goalId): Promise<void>

Removes a specific goal from the database.

Parameters

NameTypeDescription
goalId`${string}-${string}-${string}-${string}-${string}`The UUID of the goal to remove.

Returns

Promise<void>

A Promise that resolves when the goal has been removed.


removeMemory

removeMemory(memoryId, tableName): Promise<void>

Removes a specific memory from the database.

Parameters

NameTypeDescription
memoryId`${string}-${string}-${string}-${string}-${string}`The UUID of the memory to remove.
tableNamestringThe table from which the memory should be removed.

Returns

Promise<void>

A Promise that resolves when the memory has been removed.


removeParticipant

removeParticipant(user_id, room_id): Promise<boolean>

Removes a user as a participant from a specific room.

Parameters

NameTypeDescription
user_id`${string}-${string}-${string}-${string}-${string}`The UUID of the user to remove as a participant.
room_id`${string}-${string}-${string}-${string}-${string}`The UUID of the room from which the user will be removed.

Returns

Promise<boolean>

A Promise that resolves to a boolean indicating success or failure.


removeRoom

removeRoom(room_id): Promise<void>

Removes a specific room from the database.

Parameters

NameTypeDescription
room_id`${string}-${string}-${string}-${string}-${string}`The UUID of the room to remove.

Returns

Promise<void>

A Promise that resolves when the room has been removed.


searchMemories

searchMemories(params): Promise<Memory[]>

Searches for memories based on embeddings and other specified parameters.

Parameters

NameTypeDescription
paramsObjectAn object containing parameters for the memory search.
params.embeddingnumber[]-
params.match_countnumber-
params.match_thresholdnumber-
params.room_id`${string}-${string}-${string}-${string}-${string}`-
params.tableNamestring-
params.uniqueboolean-

Returns

Promise<Memory[]>

A Promise that resolves to an array of Memory objects.


searchMemoriesByEmbedding

searchMemoriesByEmbedding(embedding, params): Promise<Memory[]>

Searches for memories by embedding and other specified parameters.

Parameters

NameTypeDescription
embeddingnumber[]The embedding vector to search with.
paramsObjectAdditional parameters for the search.
params.count?number-
params.match_threshold?number-
params.room_id?`${string}-${string}-${string}-${string}-${string}`-
params.tableNamestring-
params.unique?boolean-

Returns

Promise<Memory[]>

A Promise that resolves to an array of Memory objects.


updateGoal

updateGoal(goal): Promise<void>

Updates a specific goal in the database.

Parameters

NameTypeDescription
goalGoalThe goal object with updated properties.

Returns

Promise<void>

A Promise that resolves when the goal has been updated.


updateGoalStatus

updateGoalStatus(params): Promise<void>

Updates the status of a specific goal.

Parameters

NameTypeDescription
paramsObjectAn object containing the goalId and the new status.
params.goalId`${string}-${string}-${string}-${string}-${string}`-
params.statusGoalStatus-

Returns

Promise<void>

A Promise that resolves when the goal status has been updated.