From 546dab16dcd04bca49ce6209928f915179f031eb Mon Sep 17 00:00:00 2001 From: Ian Liu Rodrigues Date: Wed, 27 Jun 2018 09:42:34 -0300 Subject: [PATCH] [pg] Add Connection abstraction Only the methods used in the "submit" function from the following projects were declared: * pg-copy-streams * pg-query-stream * pg-cursor --- types/pg/index.d.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/types/pg/index.d.ts b/types/pg/index.d.ts index ffb2379a7c..279659a9aa 100644 --- a/types/pg/index.d.ts +++ b/types/pg/index.d.ts @@ -17,6 +17,7 @@ export interface ConnectionConfig { host?: string; connectionString?: string; keepAlive?: boolean; + stream?: stream.Duplex; } export interface Defaults extends ConnectionConfig { @@ -89,6 +90,48 @@ export interface ResultBuilder extends QueryResult { addRow(row: any): void; } +export interface QueryParse { + name: string; + text: string; + types: string[]; +} + +export interface BindConfig { + portal?: string; + statement?: string; + binary?: string; + values?: Array<(Buffer | null | undefined | string)>; +} + +export interface ExecuteConfig { + portal?: string; + rows?: string; +} + +export interface MessageConfig { + type: string; + name?: string; +} + +export class Connection extends events.EventEmitter { + readonly stream: stream.Duplex; + + constructor(config?: ConnectionConfig); + + bind(config: BindConfig | null, more: boolean): void; + execute(config: ExecuteConfig | null, more: boolean): void; + parse(query: QueryParse, more: boolean): void; + + query(text: string): void; + + describe(msg: MessageConfig, more: boolean): void; + close(msg: MessageConfig, more: boolean): void; + + flush(): void; + sync(): void; + end(): void; +} + export class Pool extends events.EventEmitter { // `new Pool('pg://user@localhost/mydb')` is not allowed. // But it passes type check because of issue: