Skip to content

Commit

Permalink
Add type parameter to transaction/batch
Browse files Browse the repository at this point in the history
  • Loading branch information
DallasHoff committed Jul 20, 2024
1 parent 460c32f commit 193e35e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,22 @@ export class SQLocal {
return resultRecords as T[];
};

transaction = async (
transaction = async <T extends Record<string, any>>(
passStatements: (sql: typeof sqlTag) => Statement[]
): Promise<Record<string, unknown>[][]> => {
): Promise<T[][]> => {
const statements = passStatements(sqlTag);
const data = await this.execBatch(statements);

return data.map(({ rows, columns }) => {
return convertRowsToObjects(rows, columns);
const resultRecords = convertRowsToObjects(rows, columns);
return resultRecords as T[];
});
};

batch = async (
batch = async <T extends Record<string, any>>(
passStatements: (sql: typeof sqlTag) => Statement[]
): Promise<Record<string, unknown>[][]> => {
return await this.transaction(passStatements);
): Promise<T[][]> => {
return await this.transaction<T>(passStatements);
};

createCallbackFunction = async (
Expand Down

0 comments on commit 193e35e

Please sign in to comment.