Skip to content

Commit ba62135

Browse files
postgres updates
1 parent e580ac6 commit ba62135

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

core/src/adapters/postgres.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter {
107107
}): Promise<Memory[]> {
108108
const client = await this.pool.connect();
109109
try {
110+
if (params.roomIds.length === 0) return [];
110111
const placeholders = params.roomIds
111112
.map((_, i) => `$${i + 2}`)
112113
.join(", ");
@@ -304,7 +305,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter {
304305
`;
305306

306307
if (params.unique) {
307-
sql += " AND unique = true";
308+
sql += ` AND "unique" = true`;
308309
}
309310

310311
sql += ` AND 1 - (embedding <-> $3) >= $4
@@ -360,7 +361,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter {
360361
}
361362

362363
if (params.unique) {
363-
sql += " AND unique = true";
364+
sql += ` AND "unique" = true`;
364365
}
365366

366367
if (params.agentId) {
@@ -382,9 +383,9 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter {
382383
return rows.map((row) => ({
383384
...row,
384385
content:
385-
typeof rows.content === "string"
386-
? JSON.parse(rows.content)
387-
: rows.content,
386+
typeof row.content === "string"
387+
? JSON.parse(row.content)
388+
: row.content,
388389
}));
389390
} finally {
390391
client.release();
@@ -759,7 +760,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter {
759760
try {
760761
let sql = `SELECT COUNT(*) as count FROM memories WHERE type = $1 AND "roomId" = $2`;
761762
if (unique) {
762-
sql += " AND unique = true";
763+
sql += ` AND "unique" = true`;
763764
}
764765

765766
const { rows } = await client.query(sql, [tableName, roomId]);
@@ -796,7 +797,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter {
796797
async getRoomsForParticipants(userIds: UUID[]): Promise<UUID[]> {
797798
const client = await this.pool.connect();
798799
try {
799-
const placeholders = userIds.map((_, i) => `${i + 1}`).join(", ");
800+
const placeholders = userIds.map((_, i) => `$${i + 1}`).join(", ");
800801
const { rows } = await client.query(
801802
`SELECT DISTINCT "roomId" FROM participants WHERE "userId" IN (${placeholders})`,
802803
userIds

0 commit comments

Comments
 (0)