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
This commit is contained in:
Alex Sherwin
2018-03-01 16:40:46 -05:00
parent b122c97064
commit 6ce9368ebd
2 changed files with 11 additions and 9 deletions

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

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

View File

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