From 6ce9368ebd6dc8b6f7d4e2955a9da6dfe01d71de Mon Sep 17 00:00:00 2001 From: Alex Sherwin Date: Thu, 1 Mar 2018 16:40:46 -0500 Subject: [PATCH] Existing "QueryResult" interface is missing property "fields" only the array "QueryArrayResult" variant contained the "fields" property Added a new "QueryResultBase" interface with the shared set of fields between the single/array results and refactored both QueryResult and QueryArrayResult to extend from it, each now only needing to specify their own type variation of the "row" property for the type of results they contain (single vs array) Modified the tests to reference the "fields" array on single select results similarly to how it was done for the array select results --- types/pg/index.d.ts | 18 +++++++++--------- types/pg/pg-tests.ts | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/types/pg/index.d.ts b/types/pg/index.d.ts index b2b8af73e5..a0efbb1555 100644 --- a/types/pg/index.d.ts +++ b/types/pg/index.d.ts @@ -53,13 +53,6 @@ export interface QueryArrayConfig extends QueryConfig { rowMode: 'array'; } -export interface QueryResult { - command: string; - rowCount: number; - oid: number; - rows: any[]; -} - export interface FieldDef { name: string; tableID: number; @@ -70,14 +63,21 @@ export interface FieldDef { format: string; } -export interface QueryArrayResult { +export interface QueryResultBase { command: string; rowCount: number; oid: number; - rows: any[][]; fields: FieldDef[]; } +export interface QueryResult extends QueryResultBase { + rows: any[]; +} + +export interface QueryArrayResult extends QueryResultBase { + rows: any[][]; +} + export interface Notification { processId: number; channel: string; diff --git a/types/pg/pg-tests.ts b/types/pg/pg-tests.ts index 7f9fb04d69..f0defa0fb2 100644 --- a/types/pg/pg-tests.ts +++ b/types/pg/pg-tests.ts @@ -55,11 +55,13 @@ client.query(query, (err, res) => { console.error(err.stack); } else { console.log(res.rows); + console.log(res.fields.map(f => f.name)); } }); client.query(query) .then(res => { console.log(res.rows); + console.log(res.fields.map(f => f.name)); }) .catch(e => { console.error(e.stack);