mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
[pg] Client.query now accepts Submittables
This commit creates a new interface on @types/pg called Submittable following the description on node-postgres API doc, which says: > client.query with a Submittable > > If you pass an object to client.query and the object has a .submit > function on it, the client will pass it's PostgreSQL server connection > to the object and delegate query dispatching to the supplied object > [...] and uses the new interface as argument type to Client.query and Pool.query. This allows the usage of pg-copy-streams package.
This commit is contained in:
Vendored
+3
-1
@@ -6,6 +6,7 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import stream = require("stream");
|
||||
import pg = require("pg");
|
||||
|
||||
declare namespace QueryStream {
|
||||
interface Options {
|
||||
@@ -14,11 +15,12 @@ declare namespace QueryStream {
|
||||
}
|
||||
}
|
||||
|
||||
declare class QueryStream extends stream.Readable {
|
||||
declare class QueryStream extends stream.Readable implements pg.Submittable {
|
||||
batchSize: number;
|
||||
text: string;
|
||||
values?: any[];
|
||||
constructor(text: string, values?: any[], options?: QueryStream.Options);
|
||||
submit(connection: pg.Connection): void;
|
||||
}
|
||||
|
||||
export = QueryStream;
|
||||
|
||||
Vendored
+6
-2
@@ -51,6 +51,10 @@ export interface QueryConfig {
|
||||
values?: any[];
|
||||
}
|
||||
|
||||
export interface Submittable {
|
||||
submit: (connection: Connection) => void;
|
||||
}
|
||||
|
||||
export interface QueryArrayConfig extends QueryConfig {
|
||||
rowMode: 'array';
|
||||
}
|
||||
@@ -148,7 +152,7 @@ export class Pool extends events.EventEmitter {
|
||||
end(): Promise<void>;
|
||||
end(callback: () => void): void;
|
||||
|
||||
query(queryStream: QueryConfig & stream.Readable): stream.Readable;
|
||||
query<T extends Submittable>(queryStream: T): T;
|
||||
query(queryConfig: QueryArrayConfig): Promise<QueryArrayResult>;
|
||||
query(queryConfig: QueryConfig): Promise<QueryResult>;
|
||||
query(queryTextOrConfig: string | QueryConfig, values?: any[]): Promise<QueryResult>;
|
||||
@@ -166,7 +170,7 @@ export class ClientBase extends events.EventEmitter {
|
||||
connect(): Promise<void>;
|
||||
connect(callback: (err: Error) => void): void;
|
||||
|
||||
query(queryStream: QueryConfig & stream.Readable): stream.Readable;
|
||||
query<T extends Submittable>(queryStream: T): T;
|
||||
query(queryConfig: QueryArrayConfig): Promise<QueryArrayResult>;
|
||||
query(queryConfig: QueryConfig): Promise<QueryResult>;
|
||||
query(queryTextOrConfig: string | QueryConfig, values?: any[]): Promise<QueryResult>;
|
||||
|
||||
Reference in New Issue
Block a user