@@ -33,9 +33,10 @@ export async function executeQuery(
3333 params : unknown [ ] = [ ]
3434) : Promise < { rows : unknown [ ] ; rowCount : number } > {
3535 const result = await sql . unsafe ( query , params )
36+ const rowCount = result . count ?? result . length ?? 0
3637 return {
3738 rows : Array . isArray ( result ) ? result : [ result ] ,
38- rowCount : Array . isArray ( result ) ? result . length : result ? 1 : 0 ,
39+ rowCount,
3940 }
4041}
4142
@@ -107,9 +108,10 @@ export async function executeInsert(
107108 const query = `INSERT INTO ${ sanitizedTable } (${ sanitizedColumns . join ( ', ' ) } ) VALUES (${ placeholders . join ( ', ' ) } ) RETURNING *`
108109 const result = await sql . unsafe ( query , values )
109110
111+ const rowCount = result . count ?? result . length ?? 0
110112 return {
111113 rows : Array . isArray ( result ) ? result : [ result ] ,
112- rowCount : Array . isArray ( result ) ? result . length : result ? 1 : 0 ,
114+ rowCount,
113115 }
114116}
115117
@@ -130,9 +132,10 @@ export async function executeUpdate(
130132 const query = `UPDATE ${ sanitizedTable } SET ${ setClause } WHERE ${ where } RETURNING *`
131133 const result = await sql . unsafe ( query , values )
132134
135+ const rowCount = result . count ?? result . length ?? 0
133136 return {
134137 rows : Array . isArray ( result ) ? result : [ result ] ,
135- rowCount : Array . isArray ( result ) ? result . length : result ? 1 : 0 ,
138+ rowCount,
136139 }
137140}
138141
@@ -147,8 +150,9 @@ export async function executeDelete(
147150 const query = `DELETE FROM ${ sanitizedTable } WHERE ${ where } RETURNING *`
148151 const result = await sql . unsafe ( query , [ ] )
149152
153+ const rowCount = result . count ?? result . length ?? 0
150154 return {
151155 rows : Array . isArray ( result ) ? result : [ result ] ,
152- rowCount : Array . isArray ( result ) ? result . length : result ? 1 : 0 ,
156+ rowCount,
153157 }
154158}
0 commit comments