Skip to content

Commit 63b2dc9

Browse files
committed
feat: support parameterized query
1 parent 90a9baa commit 63b2dc9

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/bridge.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ export const createBridge = (postgres: typeof Postgres) => {
9797
},
9898
off: connection.events.off.bind(connection.events),
9999
on: connection.events.on.bind(connection.events),
100-
query: async (sql: string): Promise<QueryResult> => {
100+
query: async (sql: string, parameters): Promise<QueryResult> => {
101101
// https://github.com/porsager/postgres#result-array
102-
const resultArray = await connection.unsafe(sql);
102+
const resultArray = await connection.unsafe(sql, parameters);
103103

104104
return {
105105
command: resultArray.command as Command,

test/postgres-bridge/bridge.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,28 @@ for (const client of clients) {
132132
name: '?column?',
133133
});
134134
});
135+
136+
test(client + ': query method with parameters', async (t) => {
137+
const pool = createPool(client, {
138+
user: 'postgres',
139+
});
140+
141+
const connection = await pool.connect();
142+
143+
const result = await connection.query('SELECT $1', [
144+
'foo',
145+
]);
146+
147+
t.is(result.rows.length, 1);
148+
t.is(result.command, 'SELECT');
149+
t.like(result.rows[0],
150+
{
151+
'?column?': 'foo',
152+
});
153+
t.like(result.fields[0],
154+
{
155+
dataTypeID: 25,
156+
name: '?column?',
157+
});
158+
});
135159
}

0 commit comments

Comments
 (0)