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

Commit 175da2d0 by javiertury Committed by Sushant

fix(mariadb): named timezone support (#10705)

1 parent d6daaf1b
...@@ -54,13 +54,18 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -54,13 +54,18 @@ class ConnectionManager extends AbstractConnectionManager {
* @private * @private
*/ */
connect(config) { connect(config) {
// Named timezone is not supported in mariadb, convert to offset
let tzOffset = this.sequelize.options.timezone;
tzOffset = /\//.test(tzOffset) ? momentTz.tz(tzOffset).format('Z')
: tzOffset;
const connectionConfig = { const connectionConfig = {
host: config.host, host: config.host,
port: config.port, port: config.port,
user: config.username, user: config.username,
password: config.password, password: config.password,
database: config.database, database: config.database,
timezone: this.sequelize.options.timezone, timezone: tzOffset,
typeCast: ConnectionManager._typecast.bind(this), typeCast: ConnectionManager._typecast.bind(this),
bigNumberStrings: false, bigNumberStrings: false,
supportBigNumbers: true, supportBigNumbers: true,
...@@ -73,10 +78,6 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -73,10 +78,6 @@ class ConnectionManager extends AbstractConnectionManager {
if (!this.sequelize.config.keepDefaultTimezone) { if (!this.sequelize.config.keepDefaultTimezone) {
// set timezone for this connection // set timezone for this connection
// but named timezone are not directly supported in mariadb, so get its offset first
let tzOffset = this.sequelize.options.timezone;
tzOffset = /\//.test(tzOffset) ? momentTz.tz(tzOffset).format('Z')
: tzOffset;
if (connectionConfig.initSql) { if (connectionConfig.initSql) {
if (!Array.isArray( if (!Array.isArray(
connectionConfig.initSql)) { connectionConfig.initSql)) {
......
...@@ -38,7 +38,7 @@ if (dialect !== 'sqlite') { ...@@ -38,7 +38,7 @@ if (dialect !== 'sqlite') {
}); });
}); });
if (dialect === 'mysql') { if (dialect === 'mysql' || dialect === 'mariadb') {
it('handles existing timestamps', function() { it('handles existing timestamps', function() {
const NormalUser = this.sequelize.define('user', {}), const NormalUser = this.sequelize.define('user', {}),
TimezonedUser = this.sequelizeWithTimezone.define('user', {}); TimezonedUser = this.sequelizeWithTimezone.define('user', {});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!