Skip to content

Commit

Permalink
feat: force use of prepared statements
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jun 6, 2024
1 parent 24cca29 commit b8a1735
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/pg-driver/src/factories/createPgDriverFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ const createClientConfiguration = (
options: connectionOptions.options,
password: connectionOptions.password,
port: connectionOptions.port,
// @ts-expect-error - https://github.com/brianc/node-postgres/pull/3214
queryMode: 'extended',
ssl: false,
user: connectionOptions.username,
};
Expand Down Expand Up @@ -286,6 +284,9 @@ export const createPgDriverFactory = (): DriverFactory => {
client.on('error', onError);
client.on('notice', onNotice);

let uniqueQueryIndex = 0;
const queries: Record<string, string> = {};

return {
connect: async () => {
await client.connect();
Expand All @@ -297,10 +298,22 @@ export const createPgDriverFactory = (): DriverFactory => {
client.removeListener('notice', onNotice);
},
query: async (sql, values) => {
let queryName = queries[sql];

if (!queryName) {
queryName = `query_${++uniqueQueryIndex}`;

queries[sql] = queryName;
}

let result;

try {
result = await client.query(sql, values as unknown[]);
result = await client.query({
// name: queryName,
text: sql,
values: values as unknown[],
});
} catch (error) {
throw wrapError(error, {
sql,
Expand Down

0 comments on commit b8a1735

Please sign in to comment.