From 8112410b1ef2c493476eb08c4c35e235a4e231b7 Mon Sep 17 00:00:00 2001 From: Ankush Chadda Date: Tue, 6 Jun 2023 07:39:07 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#65348=20[pg]=20Add?= =?UTF-8?q?=20missing=20parameter=20to=20BindConfig=20by=20@iamkhush?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add valuemapper to BindConfig * fix lint errors * add test for bindconfig * add pg version * update pg-types and package version * Revert "update pg-types and package version" This reverts commit df6aa8755a5f8574a9289d737a2eefdd003e1ef6. * fix comment * revert another change --- types/pg/index.d.ts | 3 +++ types/pg/pg-tests.ts | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/types/pg/index.d.ts b/types/pg/index.d.ts index 8ff31815a6..da8d476e96 100644 --- a/types/pg/index.d.ts +++ b/types/pg/index.d.ts @@ -118,11 +118,14 @@ export interface QueryParse { types: string[]; } +type ValueMapper = (param: any, index: number) => any; + export interface BindConfig { portal?: string | undefined; statement?: string | undefined; binary?: string | undefined; values?: Array | undefined; + valueMapper?: ValueMapper | undefined; } export interface ExecuteConfig { diff --git a/types/pg/pg-tests.ts b/types/pg/pg-tests.ts index 45f387cb92..2d4b5e5183 100644 --- a/types/pg/pg-tests.ts +++ b/types/pg/pg-tests.ts @@ -1,5 +1,5 @@ import { connect } from 'net'; -import { types, Client, CustomTypesConfig, QueryArrayConfig, Pool, DatabaseError } from 'pg'; +import { types, Client, CustomTypesConfig, QueryArrayConfig, Pool, DatabaseError, Connection } from 'pg'; import TypeOverrides = require('pg/lib/type-overrides'); import { NoticeMessage } from 'pg-protocol/dist/messages'; @@ -344,3 +344,13 @@ const dynamicPasswordAsync = new Client({ password: async () => 'sync-secret', }); dynamicPasswordAsync.connect(); + +const bindConfig = { + statement: 'Select 1 from foo where bar = $1', + binary: 'false', + values: ['xyz'], + valueMapper: (param: any, index: number) => ([param, index]) +}; + +const con = new Connection(); +con.bind(bindConfig, true);