Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update v3 #82

Merged
merged 13 commits into from
Mar 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-async",
"version": "2.4.3",
"version": "3.0.0",
"description": "PostgreSQL client for node.js designed for usage with ES7 async/await based on node-postgres (pg) module",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -36,22 +36,22 @@
"homepage": "https://github.com/langpavel/node-pg-async#readme",
"dependencies": {
"bluebird": "^3.4.6",
"debug": "^2.5.0",
"pg": "^6.1.0"
"debug": "^2.6.3",
"pg": "^6.1.4"
},
"devDependencies": {
"babel": "^6.5.2",
"babel-core": "^6.7.7",
"babel-core": "^6.24.0",
"babel-eslint": "^7.1.1",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015-node5": "^1.2.0",
"babel-preset-stage-1": "^6.5.0",
"babel-register": "^6.7.2",
"babel-register": "^6.24.0",
"chai": "^3.5.0",
"del": "^2.2.0",
"eslint": "^3.1.1",
"eslint-config-strict": "^12.0.0",
"eslint-plugin-import": "^1.4.0",
"eslint-config-strict": "^13.0.0",
"eslint-plugin-import": "^2.2.0",
"estraverse-fb": "^1.3.1",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export default class PgAsync {

async getClient() {
return new Promise((resolve, reject) => {
this.getDriver().connect(this.getConnectionOptions(), (err, client, done) => {
const driver = this.getDriver();
const Pool = driver.Pool;
const pool = new Pool(this.getConnectionOptions());
pool.connect((err, client, done) => {
if (err) {
debug('%s getClient(%j)', err, this.getConnectionOptions());
if (done) done(err);
Expand Down
14 changes: 11 additions & 3 deletions test/mock/pgMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@ export class Client {
}
}

function poolFactory(driver) {
return function Pool() {
return driver;
};
};

export default class PgMock {
constructor() {
constructor(conString) {
this.conString = conString;
this.connections = 0;
this.defaults = {};
this.done = this.done.bind(this);
this.Pool = poolFactory(this);
}

connect(conString, cb) {
if (conString === 'INVALID') {
connect(cb) {
if (this.conString === 'INVALID') {
setImmediate(() => cb(new Error));
} else {
this.connections++;
Expand Down