🤖 Merge PR #65348 [pg] Add missing parameter to BindConfig by @iamkhush

* 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
This commit is contained in:
Ankush Chadda
2023-06-06 07:39:07 +02:00
committed by GitHub
parent 121aab7ac7
commit 8112410b1e
2 changed files with 14 additions and 1 deletions

3
types/pg/index.d.ts vendored
View File

@@ -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<Buffer | null | undefined | string> | undefined;
valueMapper?: ValueMapper | undefined;
}
export interface ExecuteConfig {

View File

@@ -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);