mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
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:
18
types/pg/index.d.ts
vendored
18
types/pg/index.d.ts
vendored
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user