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

Commit f5f1cb15 by Sascha Depold

refactored pg lib usage

1 parent a254cacd
Showing with 10 additions and 13 deletions
var Query = require("./query") var Query = require("./query")
, Utils = require("../../utils") , Utils = require("../../utils")
, pg = require("pg")
, without = function(arr, elem) { return arr.filter(function(e) { return e != elem }) }
module.exports = (function() { module.exports = (function() {
var ConnectorManager = function(sequelize, config) { var ConnectorManager = function(sequelize, config) {
this.sequelize = sequelize this.sequelize = sequelize
this.client = null this.client = null
this.config = config || {} this.config = config || {}
this.pooling = (this.config.poolCfg != null && this.config.poolCfg.maxConnections > 0) this.pooling = (!!this.config.poolCfg && (this.config.poolCfg.maxConnections > 0))
if (this.config.native) { this.pg = this.config.native ? require('pg').native : require('pg')
pg = pg.native
}
// set pooling parameters if specified // set pooling parameters if specified
if (this.pooling) { if (this.pooling) {
pg.defaults.poolSize = this.config.poolCfg.maxConnections this.pg.defaults.poolSize = this.config.poolCfg.maxConnections
pg.defaults.poolIdleTimeout = this.config.poolCfg.maxIdleTime this.pg.defaults.poolIdleTimeout = this.config.poolCfg.maxIdleTime
} }
this.disconnectTimeoutId = null this.disconnectTimeoutId = null
this.pendingQueries = 0 this.pendingQueries = 0
this.maxConcurrentQueries = (this.config.maxConcurrentQueries || 50) this.maxConcurrentQueries = (this.config.maxConcurrentQueries || 50)
...@@ -71,11 +69,10 @@ module.exports = (function() { ...@@ -71,11 +69,10 @@ module.exports = (function() {
if (this.pooling) { if (this.pooling) {
// acquire client from pool // acquire client from pool
pg.connect(uri, connectCallback) this.pg.connect(uri, connectCallback)
} else { } else {
//create one-off client //create one-off client
this.client = new pg.Client(uri) this.client = new this.pg.Client(uri)
this.client.connect(connectCallback) 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!