不要怂,就是干,撸起袖子干!

Commit 567ef72a by Sascha Depold

Don't overwrite pg's defaults and pass the configuration to the instance instead

1 parent 9a86b92c
Showing with 17 additions and 15 deletions
var Query = require("./query")
, Utils = require("../../utils")
var Query = require("./query")
, Utils = require("../../utils")
, ConnectionParameters = require('pg/lib/connection-parameters')
module.exports = (function() {
var ConnectorManager = function(sequelize, config) {
......@@ -16,13 +16,6 @@ module.exports = (function() {
// https://github.com/brianc/node-postgres/issues/166#issuecomment-9514935
this.pg.types.setTypeParser(20, String);
// set pooling parameters if specified
if (this.pooling) {
this.pg.defaults.poolSize = this.config.pool.maxConnections || 10
this.pg.defaults.poolIdleTimeout = this.config.pool.maxIdleTime || 30000
this.pg.defaults.reapIntervalMillis = this.config.pool.reapInterval || 1000
}
this.disconnectTimeoutId = null
this.pendingQueries = 0
this.clientDrained = true
......@@ -31,7 +24,7 @@ module.exports = (function() {
this.onProcessExit = function () {
this.disconnect()
}.bind(this);
process.on('exit', this.onProcessExit)
}
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype)
......@@ -89,7 +82,16 @@ module.exports = (function() {
this.isConnecting = true
this.isConnected = false
var uri = this.sequelize.getQueryInterface().QueryGenerator.databaseConnectionUri(this.config)
var uri = this.sequelize.getQueryInterface().QueryGenerator.databaseConnectionUri(this.config)
, config = new ConnectionParameters(uri)
// set pooling parameters if specified
if (this.pooling) {
config.poolSize = this.config.pool.maxConnections || 10
config.poolIdleTimeout = this.config.pool.maxIdleTime || 30000
config.reapIntervalMillis = this.config.pool.reapInterval || 1000
config.uuid = this.config.uuid
}
var connectCallback = function(err, client, done) {
self.isConnecting = false
......@@ -142,7 +144,7 @@ module.exports = (function() {
if (this.pooling) {
// acquire client from pool
this.pg.connect(uri, connectCallback)
this.pg.connect(config, connectCallback)
} else {
if (!!this.client) {
connectCallback(null, this.client)
......@@ -151,13 +153,13 @@ module.exports = (function() {
var responded = false
this.client = new this.pg.Client(uri)
this.client = new this.pg.Client(config)
this.client.connect(function(err, client, done) {
responded = true
connectCallback(err, client || self.client, done)
})
// If we didn't ever hear from the client.connect() callback the connection timedout, node-postgres does not treat this as an error since no active query was ever emitted
// If we didn't ever hear from the client.connect() callback the connection timeout, node-postgres does not treat this as an error since no active query was ever emitted
this.client.on('end', function () {
if (!responded) {
connectCallback(new Error('Connection timed out'))
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!