brianc / node-postgres

PostgreSQL client for node.js.
https://node-postgres.com
MIT License
12.35k stars 1.23k forks source link

event emmiter functionality #1829

Closed yuyaryshev closed 5 years ago

yuyaryshev commented 5 years ago

Here https://node-postgres.com/guides/upgrading#client-query-submittable- is described event emmiter functionality.

But in typescript is this:

export class Query extends events.EventEmitter {            // <<<<<<<<< Does not extends Submittable
    on(event: "row", listener: (row: any, result?: ResultBuilder) => void): this;
    on(event: "error", listener: (err: Error) => void): this;
    on(event: "end", listener: (result: ResultBuilder) => void): this;
}
....

// <<<<<<<<< There is no overload accepting "Query" and returning "Query"
    query<T extends Submittable>(queryStream: T): T;
    query(queryConfig: QueryArrayConfig, values?: any[]): Promise<QueryArrayResult>;
    query(queryConfig: QueryConfig): Promise<QueryResult>;
    query(queryTextOrConfig: string | QueryConfig, values?: any[]): Promise<QueryResult>;
    query(queryConfig: QueryArrayConfig, callback: (err: Error, result: QueryArrayResult) => void): Query;
    query(queryTextOrConfig: string | QueryConfig, callback: (err: Error, result: QueryResult) => void): Query;
    query(queryText: string, values: any[], callback: (err: Error, result: QueryResult) => void): Query;

Also, here: https://node-postgres.com/features/queries event emmiter functionality it's not mensioned, which is sad.

So can "event emmiter functionality" actually be used? Is it stable? How should it be used?

charmander commented 5 years ago

You would create a query object, passing it to the query<T extends Submittable>(queryStream: T): T overload and getting the same query object back. See client.query with a Submittable.