8 lines
20 KiB
Plaintext
8 lines
20 KiB
Plaintext
|
{
|
||
|
"version": 3,
|
||
|
"sources": ["../../../src/dialects/mssql/query.js"],
|
||
|
"sourcesContent": ["'use strict';\n\nconst AbstractQuery = require('../abstract/query');\nconst sequelizeErrors = require('../../errors');\nconst parserStore = require('../parserStore')('mssql');\nconst _ = require('lodash');\nconst { logger } = require('../../utils/logger');\n\nconst debug = logger.debugContext('sql:mssql');\n\nfunction getScale(aNum) {\n if (!Number.isFinite(aNum)) return 0;\n let e = 1;\n while (Math.round(aNum * e) / e !== aNum) e *= 10;\n return Math.log10(e);\n}\n\nclass Query extends AbstractQuery {\n getInsertIdField() {\n return 'id';\n }\n\n getSQLTypeFromJsType(value, TYPES) {\n const paramType = { type: TYPES.VarChar, typeOptions: {} };\n paramType.type = TYPES.NVarChar;\n if (typeof value === 'number') {\n if (Number.isInteger(value)) {\n if (value >= -2147483648 && value <= 2147483647) {\n paramType.type = TYPES.Int;\n } else {\n paramType.type = TYPES.BigInt;\n }\n } else {\n paramType.type = TYPES.Numeric;\n //Default to a reasonable numeric precision/scale pending more sophisticated logic\n paramType.typeOptions = { precision: 30, scale: getScale(value) };\n }\n } else if (typeof value === 'boolean') {\n paramType.type = TYPES.Bit;\n }\n if (Buffer.isBuffer(value)) {\n paramType.type = TYPES.VarBinary;\n }\n return paramType;\n }\n\n async _run(connection, sql, parameters, errStack) {\n this.sql = sql;\n const { options } = this;\n\n const complete = this._logQuery(sql, debug, parameters);\n\n const query = new Promise((resolve, reject) => {\n // TRANSACTION SUPPORT\n if (sql.startsWith('BEGIN TRANSACTION')) {\n return connection.beginTransaction(error => error ? reject(error) : resolve([]), options.transaction.name, connection.lib.ISOLATION_LEVEL[options.isolationLevel]);\n }\n if (sql.startsWith('COMMIT TRANSACTION')) {\n return connection.commitTransaction(error => error ? reject(error) : resolve([]));\n }\n if (sql.startsWith('ROLLBACK TRANSACTION')) {\n return connection.rollbackTransaction(error => error ? reject(error) : resolve([]), options.transaction.name);\n }\n if (sql.startsWith('SAVE TRANSACTION')) {\n return connection.saveTransaction(error => error ? reject(error) : resolve([]), options.transaction.name);\n }\n\n const rows = [];\n const request = new connection.lib.Request(sql, (err, rowCount) => err ? reject(err) : resolve([rows, rowCount]));\n\n if (parameters) {\n _.forOwn(parameters, (value, key) => {\n const paramType = this.getSQLTypeFromJsType(value, connection.lib.TYPES);\n request.addParameter(key, paramType.type, value, paramType.typeOptions);\n });\n }\n\n request.on('row', columns => {\n rows.push(columns);\n });\n\n connection.execSql(request);\n });\n\n let rows, rowCount;\n\n try {\n [rows, rowCount] = await query;\n } catch (err) {\n err.sql = sql;\n err.parameters = parameters;\n\n throw this.formatError(err, errStack);\n }\n\n complete();\n\n if (Array.isArray(rows)) {\n rows = rows.map(columns => {\n const row = {};\n for (const column of columns) {\n const typeid = column.metadata.type.id;\n const parse = parserStore.get(typeid);\n let value = column.value;\n\n if (value !== null & !!parse) {\n value = parse(value);\n }\n row[column.metadata.colName] = value;\n }\n return row;\n });\n }\n\n return this.formatResults(rows, rowCount);\n }\n\n run(sql, parameters) {\n const errForStack = new Error();\n return this.connection.queue.enqueue(() =>\n this._run(this.connection, sql, parameters, errForStack.stack)\n );\n }\n\n static formatBindParameters(sql, values, dialect) {\n const bindParam = {};\n const replacementFunc = (match, key, values) => {\n if (values[key] !== undefined) {\n bindParam[k
|
||
|
"mappings": ";AAEA,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,kBAAkB,QAAQ;AAChC,MAAM,cAAc,QAAQ,kBAAkB;AAC9C,MAAM,IAAI,QAAQ;AAClB,MAAM,EAAE,WAAW,QAAQ;AAE3B,MAAM,QAAQ,OAAO,aAAa;AAElC,kBAAkB,MAAM;AACtB,MAAI,CAAC,OAAO,SAAS;AAAO,WAAO;AACnC,MAAI,IAAI;AACR,SAAO,KAAK,MAAM,OAAO,KAAK,MAAM;AAAM,SAAK;AAC/C,SAAO,KAAK,MAAM;AAAA;AAGpB,oBAAoB,cAAc;AAAA,EAChC,mB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