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

Commit f5f1cb15 by Sascha Depold

refactored pg lib usage

1 parent a254cacd
Showing with 10 additions and 13 deletions
var Query = require("./query")
, Utils = require("../../utils")
, pg = require("pg")
, without = function(arr, elem) { return arr.filter(function(e) { return e != elem }) }
module.exports = (function() {
var ConnectorManager = function(sequelize, config) {
this.sequelize = sequelize
this.client = null
this.config = config || {}
this.pooling = (this.config.poolCfg != null && this.config.poolCfg.maxConnections > 0)
if (this.config.native) {
pg = pg.native
}
this.client = null
this.config = config || {}
this.pooling = (!!this.config.poolCfg && (this.config.poolCfg.maxConnections > 0))
this.pg = this.config.native ? require('pg').native : require('pg')
// set pooling parameters if specified
if (this.pooling) {
pg.defaults.poolSize = this.config.poolCfg.maxConnections
pg.defaults.poolIdleTimeout = this.config.poolCfg.maxIdleTime
this.pg.defaults.poolSize = this.config.poolCfg.maxConnections
this.pg.defaults.poolIdleTimeout = this.config.poolCfg.maxIdleTime
}
this.disconnectTimeoutId = null
this.pendingQueries = 0
this.maxConcurrentQueries = (this.config.maxConcurrentQueries || 50)
......@@ -71,11 +69,10 @@ module.exports = (function() {
if (this.pooling) {
// acquire client from pool
pg.connect(uri, connectCallback)
this.pg.connect(uri, connectCallback)
} else {
//create one-off client
this.client = new pg.Client(uri)
this.client = new this.pg.Client(uri)
this.client.connect(connectCallback)
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!