Skip to content

Commit bc4c482

Browse files
authored
Merge pull request #173 from minghinmatthewlam/main
postgres updates
2 parents b00d1ea + 3b2d129 commit bc4c482

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

core/src/adapters/postgres.ts

+12-11
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
@@ -349,18 +350,18 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter {
349350

350351
if (params.start) {
351352
paramCount++;
352-
sql += ` AND "createdAt" >= to_timestamp($${paramCount / 1000})`;
353-
values.push(params.start);
353+
sql += ` AND "createdAt" >= to_timestamp($${paramCount})`;
354+
values.push(params.start/1000);
354355
}
355356

356357
if (params.end) {
357358
paramCount++;
358-
sql += ` AND "createdAt" <= to_timestamp($${paramCount / 1000})`;
359-
values.push(params.end);
359+
sql += ` AND "createdAt" <= to_timestamp($${paramCount})`;
360+
values.push(params.end/1000);
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)