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

Commit 2f3d587f by Sascha Depold

set the timezone after transaction setup

1 parent f0352b2f
Showing with 16 additions and 2 deletions
...@@ -68,6 +68,10 @@ module.exports = (function() { ...@@ -68,6 +68,10 @@ module.exports = (function() {
}).run() }).run()
} }
ConnectorManager.prototype.afterTransactionSetup = function(callback) {
this.setTimezone(this.client, 'UTC', callback)
}
ConnectorManager.prototype.connect = function(callback) { ConnectorManager.prototype.connect = function(callback) {
var self = this var self = this
var emitter = new (require('events').EventEmitter)() var emitter = new (require('events').EventEmitter)()
...@@ -108,11 +112,17 @@ module.exports = (function() { ...@@ -108,11 +112,17 @@ module.exports = (function() {
} }
} }
} else if (client) { } else if (client) {
client.query("SET TIME ZONE 'UTC'").on('end', function() { var timezoneCallback = function() {
self.isConnected = true self.isConnected = true
self.client = client self.client = client
emitter.emit('success', done) emitter.emit('success', done)
}) }
if (self.config.keepDefaultTimezone) {
Utils.tick(timezoneCallback)
} else {
self.setTimezone(client, 'UTC', timezoneCallback)
}
} else { } else {
done && done() done && done()
self.client = null self.client = null
...@@ -136,6 +146,10 @@ module.exports = (function() { ...@@ -136,6 +146,10 @@ module.exports = (function() {
return emitter return emitter
} }
ConnectorManager.prototype.setTimezone = function(client, timezone, callback) {
client.query("SET TIME ZONE '" + (timezone || "UTC") + "'").on('end', callback)
}
ConnectorManager.prototype.disconnect = function() { ConnectorManager.prototype.disconnect = function() {
if (this.poolIdentifier) { if (this.poolIdentifier) {
this.poolIdentifier.destroyAllNow() this.poolIdentifier.destroyAllNow()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!