Skip to content

Commit 06aeacf

Browse files
committedNov 24, 2024
fix: null issue
1 parent 19e9d1b commit 06aeacf

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed
 

‎packages/adapter-postgres/src/index.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,16 @@ export class PostgresDatabaseAdapter
5959
while (retryCount < maxRetries) {
6060
try {
6161
const delay = baseDelay * Math.pow(2, retryCount);
62-
elizaLogger.log(`Attempting to reconnect in ${delay}ms...`);
62+
elizaLogger.warn(
63+
`Attempting to reconnect in ${delay}ms...`
64+
);
6365
await new Promise((resolve) => setTimeout(resolve, delay));
6466

6567
// Create new pool with same config
6668
this.pool = new pg.Pool(this.pool.options);
6769
await this.testConnection();
6870

69-
elizaLogger.log("Successfully reconnected to database");
71+
elizaLogger.success("Successfully reconnected to database");
7072
return;
7173
} catch (error) {
7274
retryCount++;
@@ -116,7 +118,7 @@ export class PostgresDatabaseAdapter
116118
try {
117119
client = await this.pool.connect();
118120
const result = await client.query("SELECT NOW()");
119-
elizaLogger.log(
121+
elizaLogger.success(
120122
"Database connection test successful:",
121123
result.rows[0]
122124
);
@@ -215,7 +217,7 @@ export class PostgresDatabaseAdapter
215217
if (rows.length === 0) return null;
216218

217219
const account = rows[0];
218-
elizaLogger.log("account", account);
220+
elizaLogger.debug("account", account);
219221
return {
220222
...account,
221223
details:
@@ -346,7 +348,7 @@ export class PostgresDatabaseAdapter
346348
if (!params.roomId) throw new Error("roomId is required");
347349
let sql = `SELECT * FROM memories WHERE type = $1 AND "agentId" = $2 AND "roomId" = $3`;
348350
const values: any[] = [params.tableName, params.agentId, params.roomId];
349-
let paramCount = 2;
351+
let paramCount = 3; // Updated to start at 3 since we already have 3 parameters
350352

351353
if (params.start) {
352354
paramCount++;
@@ -366,9 +368,9 @@ export class PostgresDatabaseAdapter
366368

367369
sql += ' ORDER BY "createdAt" DESC';
368370

369-
if (params.count) {
371+
if (params.count && typeof params.count === "number") {
370372
paramCount++;
371-
sql += ` LIMIT $${paramCount}`;
373+
sql += ` LIMIT $${paramCount}::integer`; // Cast to integer
372374
values.push(params.count);
373375
}
374376

@@ -628,7 +630,7 @@ export class PostgresDatabaseAdapter
628630
);
629631

630632
if (existingParticipant.rows.length > 0) {
631-
elizaLogger.log(
633+
elizaLogger.error(
632634
`Participant with userId ${userId} already exists in room ${roomId}.`
633635
);
634636
return true; // Exit early if the participant already exists
@@ -643,7 +645,7 @@ export class PostgresDatabaseAdapter
643645
return true;
644646
} catch (error) {
645647
if (error instanceof DatabaseError) {
646-
elizaLogger.log("Error adding participant", error);
648+
elizaLogger.error("Error adding participant", error);
647649
// This is to prevent duplicate participant error in case of a race condition
648650
// Handle unique constraint violation error (code 23505)
649651
if (error.code === "23505") {

0 commit comments

Comments
 (0)