You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

7 lines
6.3 KiB

{
"version": 3,
"sources": ["../../../src/dialects/mariadb/connection-manager.js"],
"sourcesContent": ["'use strict';\n\nconst semver = require('semver');\nconst AbstractConnectionManager = require('../abstract/connection-manager');\nconst SequelizeErrors = require('../../errors');\nconst { logger } = require('../../utils/logger');\nconst DataTypes = require('../../data-types').mariadb;\nconst momentTz = require('moment-timezone');\nconst debug = logger.debugContext('connection:mariadb');\nconst parserStore = require('../parserStore')('mariadb');\n\n/**\n * MariaDB Connection Manager\n *\n * Get connections, validate and disconnect them.\n * AbstractConnectionManager pooling use it to handle MariaDB specific connections\n * Use https://github.com/MariaDB/mariadb-connector-nodejs to connect with MariaDB server\n *\n * @private\n */\nclass ConnectionManager extends AbstractConnectionManager {\n constructor(dialect, sequelize) {\n sequelize.config.port = sequelize.config.port || 3306;\n super(dialect, sequelize);\n this.lib = this._loadDialectModule('mariadb');\n this.refreshTypeParser(DataTypes);\n }\n\n static _typecast(field, next) {\n if (parserStore.get(field.type)) {\n return parserStore.get(field.type)(field, this.sequelize.options, next);\n }\n return next();\n }\n\n _refreshTypeParser(dataType) {\n parserStore.refresh(dataType);\n }\n\n _clearTypeParser() {\n parserStore.clear();\n }\n\n /**\n * Connect with MariaDB database based on config, Handle any errors in connection\n * Set the pool handlers on connection.error\n * Also set proper timezone once connection is connected.\n *\n * @param {object} config\n * @returns {Promise<Connection>}\n * @private\n */\n async connect(config) {\n // Named timezone is not supported in mariadb, convert to offset\n let tzOffset = this.sequelize.options.timezone;\n tzOffset = /\\//.test(tzOffset) ? momentTz.tz(tzOffset).format('Z')\n : tzOffset;\n\n const connectionConfig = {\n host: config.host,\n port: config.port,\n user: config.username,\n password: config.password,\n database: config.database,\n timezone: tzOffset,\n typeCast: ConnectionManager._typecast.bind(this),\n bigNumberStrings: false,\n supportBigNumbers: true,\n foundRows: false,\n ...config.dialectOptions\n };\n\n if (!this.sequelize.config.keepDefaultTimezone) {\n // set timezone for this connection\n if (connectionConfig.initSql) {\n if (!Array.isArray(\n connectionConfig.initSql)) {\n connectionConfig.initSql = [connectionConfig.initSql];\n }\n connectionConfig.initSql.push(`SET time_zone = '${tzOffset}'`);\n } else {\n connectionConfig.initSql = `SET time_zone = '${tzOffset}'`;\n }\n }\n\n try {\n const connection = await this.lib.createConnection(connectionConfig);\n this.sequelize.options.databaseVersion = semver.coerce(connection.serverVersion()).version;\n\n debug('connection acquired');\n connection.on('error', error => {\n switch (error.code) {\n case 'ESOCKET':\n case 'ECONNRESET':\n case 'EPIPE':\n case 'PROTOCOL_CONNECTION_LOST':\n this.pool.destroy(connection);\n }\n });\n return connection;\n } catch (err) {\n switch (err.code) {\n case 'ECONNREFUSED':\n throw new SequelizeErrors.ConnectionRefusedError(err);\n case 'ER_ACCESS_DENIED_ERROR':\n case 'ER_ACCESS_DENIED_NO_PASSWORD_ERROR':\n throw new SequelizeErrors.AccessDeniedError(err);\n case 'ENOTFOUND':\n throw new SequelizeErrors.HostNotFoundError(err);\n case 'EHOSTUNREACH':\n case 'ENETUNREACH':\n case 'EADDRNOTAVAIL':\n throw new SequelizeErrors.HostNotReachableError(err);\n case 'EINVAL':\n throw new SequelizeErrors.InvalidConnectionError(err);\n default:\n throw new SequelizeErrors.ConnectionError(err);\n }\n }\n }\n\n async disconnect(connection) {\n // Don't disconnect connections with CLOSED state\n if (!connection.isValid()) {\n debug('connection tried to disconnect but was already at CLOSED state');\n return;\n }\n return await connection.end();\n }\n\n validate(connection) {\n return connection && connection.isValid();\n }\n}\n\nmodule.exports = ConnectionManager;\nmodule.exports.ConnectionManager = ConnectionManager;\nmodule.exports.default = ConnectionManager;\n"],
"mappings": ";;;;;;;;;;;;;;;;;AAEA,MAAM,SAAS,QAAQ;AACvB,MAAM,4BAA4B,QAAQ;AAC1C,MAAM,kBAAkB,QAAQ;AAChC,MAAM,EAAE,WAAW,QAAQ;AAC3B,MAAM,YAAY,QAAQ,oBAA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