Skip to content

Commit

Permalink
Remove usage of normalizeStatement for now
Browse files Browse the repository at this point in the history
  • Loading branch information
DallasHoff committed Jul 20, 2024
1 parent 15e5fc4 commit 460c32f
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ import type {
ScalarUserFunction,
GetInfoMessage,
Statement,
ReturningStatement,
DatabaseInfo,
} from './types.js';
import { sqlTag } from './lib/sql-tag.js';
import { convertRowsToObjects } from './lib/convert-rows-to-objects.js';
import { normalizeStatement } from './lib/normalize-statement.js';

export class SQLocal {
protected databasePath: string;
Expand Down Expand Up @@ -179,15 +177,6 @@ export class SQLocal {
return data;
};

protected execAndConvert = async <T extends Record<string, any>>(
statement: ReturningStatement<T>
): Promise<T[]> => {
const { sql, params } = normalizeStatement(statement);
const { rows, columns } = await this.exec(sql, params, 'all');
const resultRecords = convertRowsToObjects(rows, columns);
return resultRecords as T[];
};

sql = async <T extends Record<string, any>>(
queryTemplate: TemplateStringsArray | string,
...params: unknown[]
Expand All @@ -200,8 +189,13 @@ export class SQLocal {
statement = sqlTag(queryTemplate, ...params);
}

const resultRecords = await this.execAndConvert<T>(statement);
return resultRecords;
const { rows, columns } = await this.exec(
statement.sql,
statement.params,
'all'
);
const resultRecords = convertRowsToObjects(rows, columns);
return resultRecords as T[];
};

transaction = async (
Expand Down

0 comments on commit 460c32f

Please sign in to comment.