8 lines
8.2 KiB
Plaintext
8 lines
8.2 KiB
Plaintext
|
{
|
||
|
"version": 3,
|
||
|
"sources": ["../../../src/dialects/mssql/connection-manager.js"],
|
||
|
"sourcesContent": ["'use strict';\n\nconst AbstractConnectionManager = require('../abstract/connection-manager');\nconst AsyncQueue = require('./async-queue').default;\nconst { logger } = require('../../utils/logger');\nconst sequelizeErrors = require('../../errors');\nconst DataTypes = require('../../data-types').mssql;\nconst parserStore = require('../parserStore')('mssql');\nconst debug = logger.debugContext('connection:mssql');\nconst debugTedious = logger.debugContext('connection:mssql:tedious');\n\nclass ConnectionManager extends AbstractConnectionManager {\n constructor(dialect, sequelize) {\n sequelize.config.port = sequelize.config.port || 1433;\n super(dialect, sequelize);\n this.lib = this._loadDialectModule('tedious');\n this.refreshTypeParser(DataTypes);\n }\n\n _refreshTypeParser(dataType) {\n parserStore.refresh(dataType);\n }\n\n _clearTypeParser() {\n parserStore.clear();\n }\n\n async connect(config) {\n const connectionConfig = {\n server: config.host,\n authentication: {\n type: 'default',\n options: {\n userName: config.username || undefined,\n password: config.password || undefined\n }\n },\n options: {\n port: parseInt(config.port, 10),\n database: config.database,\n trustServerCertificate: true\n }\n };\n\n if (config.dialectOptions) {\n // only set port if no instance name was provided\n if (\n config.dialectOptions.options &&\n config.dialectOptions.options.instanceName\n ) {\n delete connectionConfig.options.port;\n }\n\n if (config.dialectOptions.authentication) {\n Object.assign(connectionConfig.authentication, config.dialectOptions.authentication);\n }\n\n Object.assign(connectionConfig.options, config.dialectOptions.options);\n }\n\n try {\n return await new Promise((resolve, reject) => {\n const connection = new this.lib.Connection(connectionConfig);\n if (connection.state === connection.STATE.INITIALIZED) {\n connection.connect();\n }\n connection.queue = new AsyncQueue();\n connection.lib = this.lib;\n\n const connectHandler = error => {\n connection.removeListener('end', endHandler);\n connection.removeListener('error', errorHandler);\n\n if (error) return reject(error);\n\n debug('connection acquired');\n resolve(connection);\n };\n\n const endHandler = () => {\n connection.removeListener('connect', connectHandler);\n connection.removeListener('error', errorHandler);\n reject(new Error('Connection was closed by remote server'));\n };\n\n const errorHandler = error => {\n connection.removeListener('connect', connectHandler);\n connection.removeListener('end', endHandler);\n reject(error);\n };\n\n connection.once('error', errorHandler);\n connection.once('end', endHandler);\n connection.once('connect', connectHandler);\n\n /*\n * Permanently attach this event before connection is even acquired\n * tedious sometime emits error even after connect(with error).\n *\n * If we dont attach this even that unexpected error event will crash node process\n *\n * E.g. connectTimeout is set higher than requestTimeout\n */\n connection.on('error', error => {\n switch (error.code) {\n case 'ESOCKET':\n case 'ECONNRESET':\n this.pool.destroy(connection);\n }\n });\n\n if (config.dialectOptions && config.dialectOptions.debug) {\n connection.on('debug', debugTedious.log.bind(debugTedious));\n }\n });\n } catch (error) {\n if (!error.code) {\n throw new sequelizeErrors.ConnectionError(error);\n }\n\n switch (error.code) {\n case 'ESOCKET':\n if (error.message.includes('connect EHOSTUNREACH')) {\n throw ne
|
||
|
"mappings": ";AAEA,MAAM,4BAA4B,QAAQ;AAC1C,MAAM,aAAa,QAAQ,iBAAiB;AAC5C,MAAM,EAAE,WAAW,QAAQ;AAC3B,MAAM,kBAAkB,QAAQ;AAChC,MAAM,YAAY,QAAQ,oBAAoB;AAC9C,MAAM,cAAc,QAAQ,kBAAkB;AAC9C,MAAM,QAAQ,OAAO,aAAa;AAClC,MAAM,eAAe,OAAO,aAAa;AAEzC,gCAAgC,0BAA0B;AAAA,EACxD,YAAY,SAAS,WAAW;AAC9B,cAAU,OAAO,OAAO,UAAU,OAAO,QAAQ;AACjD,UAAM,SAAS;AACf,SAAK,MAAM,KAAK,mBAAmB;AACnC,SAAK,kBAAkB;AAAA;AAAA,EAGzB,mBAAmB,UAAU;AAC3B,gBAAY,QAAQ;AAAA;AAAA,EAGtB,mBAAmB;AACjB,gBAAY;AAAA;AAAA,QAGR,QAAQ,QAAQ;AACpB,UAAM,mBAAmB;AAAA,MACvB,QAAQ,OAAO;AAAA,MACf,gBAAgB;AAAA,QACd,MAAM;AAAA,QACN,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