diff --git a/packages/runtime/src/tag.ts b/packages/runtime/src/tag.ts index 26619574..27395d28 100644 --- a/packages/runtime/src/tag.ts +++ b/packages/runtime/src/tag.ts @@ -8,7 +8,10 @@ export interface ICursor { } export interface IDatabaseConnection { - query: (query: string, bindings: any[]) => Promise<{ rows: any[] }>; + query: ( + query: string, + bindings: any[], + ) => Promise<{ rows: any[]; rowCount: number }>; stream?: (query: string, bindings: any[]) => ICursor; } @@ -95,6 +98,11 @@ export class PreparedQuery { dbConnection: IDatabaseConnection, ) => Promise>; + public runWithCounts: ( + params: TParamType, + dbConnection: IDatabaseConnection, + ) => Promise<{ result: Array; rowCount: number }>; + public stream: ( params: TParamType, dbConnection: IDatabaseConnection, @@ -112,6 +120,17 @@ export class PreparedQuery { const result = await connection.query(processedQuery, bindings); return mapQueryResultRows(result.rows); }; + this.runWithCounts = async (params, connection) => { + const { query: processedQuery, bindings } = processSQLQueryIR( + this.queryIR, + params as any, + ); + const result = await connection.query(processedQuery, bindings); + return { + result: mapQueryResultRows(result.rows), + rowCount: result.rowCount, + }; + }; this.stream = (params, connection) => { const { query: processedQuery, bindings } = processSQLQueryIR( this.queryIR,