Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import EventEmitter = require("events");
import stream = require("stream");
import pg = require("pg");

declare interface TlsOptions {
rejectUnauthorized?: boolean;
Expand Down Expand Up @@ -75,7 +77,7 @@ declare namespace ServerlessClient {
export { TlsOptions, Config };
}

declare class ServerlessClient {
declare class ServerlessClient extends EventEmitter {
constructor(config: Config)

clean(): Promise<number | undefined>
Expand All @@ -88,7 +90,7 @@ declare class ServerlessClient {

end(): Promise<any>

on(...args): void
on(event: "init", listener: (client: pg.Client) => void): this
}

export = ServerlessClient
18 changes: 10 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
* @license MIT
*/

const EventEmitter = require("events");
const {isValidStrategy, type, validateNum, isWithinRange} = require("./utils");
const Postgres = require("./postgres");

function ServerlessClient(config) {
EventEmitter.call(this);

this._client = null;
if (config.plugin) {
this._plugin = config.plugin
Expand All @@ -20,6 +23,9 @@ function ServerlessClient(config) {
this.setConfig(config)
}

ServerlessClient.prototype = Object.create(EventEmitter.prototype);
ServerlessClient.prototype.constructor = ServerlessClient;

ServerlessClient.prototype.constructor = ServerlessClient;
ServerlessClient.prototype._sleep = delay =>
new Promise(resolve => {
Expand Down Expand Up @@ -201,6 +207,7 @@ ServerlessClient.prototype._init = async function () {
await this._setMaxConnections(this)
}

this.emit("init", this._client);
this._logger("Max connections: ", this._maxConns.cache.total)
}

Expand Down Expand Up @@ -423,8 +430,4 @@ ServerlessClient.prototype.end = async function () {
this._client = null
}

ServerlessClient.prototype.on = function (...args) {
this._client.on(...args)
}

module.exports = {ServerlessClient};