Skip to content

Commit 315bd2a

Browse files
author
Raymond Feng
committed
1 parent 16218d2 commit 315bd2a

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

lib/postgresql.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ function PostgreSQL(postgresql, settings) {
6868
// this._models = {};
6969
// this.settings = settings;
7070
this.constructor.super_.call(this, 'postgresql', settings);
71-
this.clientConfig = settings.url || settings;
71+
if (settings.url) {
72+
// pg-pool doesn't handle string config correctly
73+
this.clientConfig = {
74+
connectionString: settings.url
75+
}
76+
} else {
77+
this.clientConfig = settings;
78+
}
7279
this.pg = new postgresql.Pool(this.clientConfig);
7380
this.settings = settings;
7481
if (settings.debug) {

test/init.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ if (process.env.CI) {
1717
};
1818
}
1919

20-
global.getDataSource = global.getSchema = function () {
20+
var url = 'postgres://' + config.username || config.user + ':' +
21+
config.password + '@' + config.host || config.hostname + ':' +
22+
config.port + '/' + config.database;
23+
24+
global.getDataSource = global.getSchema = function(useUrl) {
25+
var settings = config;
26+
if (useUrl) {
27+
settings = {url: url};
28+
}
2129
var db = new DataSource(require('../'), config);
22-
db.log = function (a) {
30+
db.log = function(a) {
2331
// console.log(a);
2432
};
2533
return db;

test/postgresql.transaction.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var db, Post;
1313
describe('transactions', function() {
1414

1515
before(function(done) {
16-
db = getDataSource();
16+
db = getDataSource(true);
1717
Post = db.define('PostTX', {
1818
title: {type: String, length: 255, index: true},
1919
content: {type: String}

0 commit comments

Comments
 (0)