From c592e54118d5610b69fa07fc42bbe64015bda316 Mon Sep 17 00:00:00 2001 From: Waleed Date: Thu, 11 Dec 2025 14:03:00 -0800 Subject: [PATCH] fix(pg): for pg tools, use count isntead of length for number of rows impacted (#2317) --- apps/sim/app/api/tools/postgresql/utils.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/sim/app/api/tools/postgresql/utils.ts b/apps/sim/app/api/tools/postgresql/utils.ts index 91956de20..02d421ad4 100644 --- a/apps/sim/app/api/tools/postgresql/utils.ts +++ b/apps/sim/app/api/tools/postgresql/utils.ts @@ -33,9 +33,10 @@ export async function executeQuery( params: unknown[] = [] ): Promise<{ rows: unknown[]; rowCount: number }> { const result = await sql.unsafe(query, params) + const rowCount = result.count ?? result.length ?? 0 return { rows: Array.isArray(result) ? result : [result], - rowCount: Array.isArray(result) ? result.length : result ? 1 : 0, + rowCount, } } @@ -107,9 +108,10 @@ export async function executeInsert( const query = `INSERT INTO ${sanitizedTable} (${sanitizedColumns.join(', ')}) VALUES (${placeholders.join(', ')}) RETURNING *` const result = await sql.unsafe(query, values) + const rowCount = result.count ?? result.length ?? 0 return { rows: Array.isArray(result) ? result : [result], - rowCount: Array.isArray(result) ? result.length : result ? 1 : 0, + rowCount, } } @@ -130,9 +132,10 @@ export async function executeUpdate( const query = `UPDATE ${sanitizedTable} SET ${setClause} WHERE ${where} RETURNING *` const result = await sql.unsafe(query, values) + const rowCount = result.count ?? result.length ?? 0 return { rows: Array.isArray(result) ? result : [result], - rowCount: Array.isArray(result) ? result.length : result ? 1 : 0, + rowCount, } } @@ -147,8 +150,9 @@ export async function executeDelete( const query = `DELETE FROM ${sanitizedTable} WHERE ${where} RETURNING *` const result = await sql.unsafe(query, []) + const rowCount = result.count ?? result.length ?? 0 return { rows: Array.isArray(result) ? result : [result], - rowCount: Array.isArray(result) ? result.length : result ? 1 : 0, + rowCount, } }