mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
Merge pull request #14469 from SaschaNaz/patch-1
Introduce `default` field on pg
This commit is contained in:
Vendored
+17
-28
@@ -1,11 +1,9 @@
|
||||
// Type definitions for pg 6.1.0
|
||||
// Type definitions for pg 6.1
|
||||
// Project: https://github.com/brianc/node-postgres
|
||||
// Definitions by: Phips Peter <http://pspeter3.com>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
/// <reference types="pg-types" />
|
||||
|
||||
|
||||
import events = require("events");
|
||||
import stream = require("stream");
|
||||
@@ -63,44 +61,38 @@ export interface ResultBuilder extends QueryResult {
|
||||
}
|
||||
|
||||
export declare class Pool extends events.EventEmitter {
|
||||
|
||||
constructor();
|
||||
|
||||
// `new Pool('pg://user@localhost/mydb')` is not allowed.
|
||||
// But it passes type check because of issue:
|
||||
// https://github.com/Microsoft/TypeScript/issues/7485
|
||||
constructor(config: PoolConfig);
|
||||
constructor(config?: PoolConfig);
|
||||
|
||||
connect(): Promise<Client>;
|
||||
connect(callback: (err: Error, client: Client, done: () => void) => void): void;
|
||||
|
||||
end(): Promise<void>;
|
||||
|
||||
query(queryText: string): Promise<QueryResult>;
|
||||
query(queryText: string, values: any[]): Promise<QueryResult>;
|
||||
query(queryText: string, values?: any[]): Promise<QueryResult>;
|
||||
|
||||
query(queryText: string, callback: (err: Error, result: QueryResult) => void): void;
|
||||
query(queryText: string, values: any[], callback: (err: Error, result: QueryResult) => void): void;
|
||||
|
||||
public on(event: "error", listener: (err: Error, client: Client) => void): this;
|
||||
public on(event: "connect", listener: (client: Client) => void): this;
|
||||
public on(event: "acquire", listener: (client: Client) => void): this;
|
||||
public on(event: string, listener: Function): this;
|
||||
on(event: "error", listener: (err: Error, client: Client) => void): this;
|
||||
on(event: "connect" | "acquire", listener: (client: Client) => void): this;
|
||||
}
|
||||
|
||||
export declare class Client extends events.EventEmitter {
|
||||
constructor(connection: string);
|
||||
constructor(config: ClientConfig);
|
||||
|
||||
connect(callback?: (err:Error) => void): void;
|
||||
connect(callback?: (err: Error) => void): void;
|
||||
end(callback?: (err: Error) => void): void;
|
||||
release(): void;
|
||||
|
||||
query(queryTextOrConfig: string | QueryConfig): Promise<QueryResult>;
|
||||
query(queryText: string, values: any[]): Promise<QueryResult>;
|
||||
|
||||
query(queryTextOrConfig: string | QueryConfig, callback?: (err: Error, result: QueryResult) => void): Query;
|
||||
query(queryText: string, values: any[], callback?: (err: Error, result: QueryResult) => 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;
|
||||
|
||||
copyFrom(queryText: string): stream.Writable;
|
||||
copyTo(queryText: string): stream.Readable;
|
||||
@@ -108,25 +100,22 @@ export declare class Client extends events.EventEmitter {
|
||||
pauseDrain(): void;
|
||||
resumeDrain(): void;
|
||||
|
||||
public on(event: "drain", listener: () => void): this;
|
||||
public on(event: "error", listener: (err: Error) => void): this;
|
||||
public on(event: "notification", listener: (message: any) => void): this;
|
||||
public on(event: "notice", listener: (message: any) => void): this;
|
||||
public on(event: string, listener: Function): this;
|
||||
on(event: "drain", listener: () => void): this;
|
||||
on(event: "error", listener: (err: Error) => void): this;
|
||||
on(event: "notification" | "notice", listener: (message: any) => void): this;
|
||||
on(event: "end", listener: () => void): this;
|
||||
}
|
||||
|
||||
export declare class Query extends events.EventEmitter {
|
||||
public on(event: "row", listener: (row: any, result?: ResultBuilder) => void): this;
|
||||
public on(event: "error", listener: (err: Error) => void): this;
|
||||
public on(event: "end", listener: (result: ResultBuilder) => void): this;
|
||||
public on(event: string, listener: Function): this;
|
||||
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;
|
||||
}
|
||||
|
||||
export declare class Events extends events.EventEmitter {
|
||||
public on(event: "error", listener: (err: Error, client: Client) => void): this;
|
||||
public on(event: string, listener: Function): this;
|
||||
on(event: "error", listener: (err: Error, client: Client) => void): this;
|
||||
}
|
||||
|
||||
export const types: typeof pgTypes;
|
||||
|
||||
|
||||
export const defaults: Defaults & ClientConfig;
|
||||
|
||||
+8
-6
@@ -4,9 +4,10 @@ import * as pg from "pg";
|
||||
var conString = "postgres://username:password@localhost/database";
|
||||
|
||||
// https://github.com/brianc/node-pg-types
|
||||
pg.types.setTypeParser(20, (val) => Number(val));
|
||||
pg.types.setTypeParser(20, val => Number(val));
|
||||
|
||||
// Client pooling
|
||||
pg.defaults.ssl = true;
|
||||
pg.connect(conString, (err, client, done) => {
|
||||
if (err) {
|
||||
return console.error("Error fetching client from pool", err);
|
||||
@@ -27,7 +28,7 @@ pg.connect(conString, (err, client, done) => {
|
||||
|
||||
// Simple
|
||||
var client = new pg.Client(conString);
|
||||
client.connect((err) => {
|
||||
client.connect(err => {
|
||||
if (err) {
|
||||
return console.error("Could not connect to postgres", err);
|
||||
}
|
||||
@@ -42,6 +43,7 @@ client.connect((err) => {
|
||||
});
|
||||
return null;
|
||||
});
|
||||
client.on('end', () => console.log("Client was disconnected."));
|
||||
|
||||
// client pooling
|
||||
|
||||
@@ -55,11 +57,11 @@ var config = {
|
||||
};
|
||||
var pool = new pg.Pool(config);
|
||||
|
||||
pool.connect(function(err, client, done) {
|
||||
pool.connect((err, client, done) => {
|
||||
if(err) {
|
||||
return console.error('error fetching client from pool', err);
|
||||
}
|
||||
client.query('SELECT $1::int AS number', ['1'], function(err, result) {
|
||||
client.query('SELECT $1::int AS number', ['1'], (err, result) => {
|
||||
done();
|
||||
|
||||
if(err) {
|
||||
@@ -69,6 +71,6 @@ pool.connect(function(err, client, done) {
|
||||
});
|
||||
});
|
||||
|
||||
pool.on('error', function (err, client) {
|
||||
pool.on('error', (err, client) => {
|
||||
console.error('idle client error', err.message, err.stack)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user