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.
8 lines
21 KiB
8 lines
21 KiB
2 years ago
|
{
|
||
|
"version": 3,
|
||
|
"sources": ["../../../src/dialects/postgres/query.js"],
|
||
|
"sourcesContent": ["'use strict';\n\nconst AbstractQuery = require('../abstract/query');\nconst QueryTypes = require('../../query-types');\nconst sequelizeErrors = require('../../errors');\nconst _ = require('lodash');\nconst { logger } = require('../../utils/logger');\n\nconst debug = logger.debugContext('sql:pg');\n\n\nclass Query extends AbstractQuery {\n /**\n * Rewrite query with parameters.\n *\n * @param {string} sql\n * @param {Array|object} values\n * @param {string} dialect\n * @private\n */\n static formatBindParameters(sql, values, dialect) {\n const stringReplaceFunc = value => typeof value === 'string' ? value.replace(/\\0/g, '\\\\0') : value;\n\n let bindParam;\n if (Array.isArray(values)) {\n bindParam = values.map(stringReplaceFunc);\n sql = AbstractQuery.formatBindParameters(sql, values, dialect, { skipValueReplace: true })[0];\n } else {\n bindParam = [];\n let i = 0;\n const seen = {};\n const replacementFunc = (match, key, values) => {\n if (seen[key] !== undefined) {\n return seen[key];\n }\n if (values[key] !== undefined) {\n i = i + 1;\n bindParam.push(stringReplaceFunc(values[key]));\n seen[key] = `$${i}`;\n return `$${i}`;\n }\n return undefined;\n };\n sql = AbstractQuery.formatBindParameters(sql, values, dialect, replacementFunc)[0];\n }\n return [sql, bindParam];\n }\n\n async run(sql, parameters) {\n const { connection } = this;\n\n if (!_.isEmpty(this.options.searchPath)) {\n sql = this.sequelize.getQueryInterface().queryGenerator.setSearchPath(this.options.searchPath) + sql;\n }\n\n if (this.sequelize.options.minifyAliases && this.options.includeAliases) {\n _.toPairs(this.options.includeAliases)\n // Sorting to replace the longest aliases first to prevent alias collision\n .sort((a, b) => b[1].length - a[1].length)\n .forEach(([alias, original]) => {\n const reg = new RegExp(_.escapeRegExp(original), 'g');\n\n sql = sql.replace(reg, alias);\n });\n }\n\n this.sql = sql;\n\n const query = parameters && parameters.length\n ? new Promise((resolve, reject) => connection.query(sql, parameters, (error, result) => error ? reject(error) : resolve(result)))\n : new Promise((resolve, reject) => connection.query(sql, (error, result) => error ? reject(error) : resolve(result)));\n\n const complete = this._logQuery(sql, debug, parameters);\n\n let queryResult;\n const errForStack = new Error();\n\n try {\n queryResult = await query;\n } catch (error) {\n // set the client so that it will be reaped if the connection resets while executing\n if (error.code === 'ECONNRESET'\n // https://github.com/sequelize/sequelize/pull/14090\n // pg-native throws custom exception or libpq formatted errors\n || /Unable to set non-blocking to true/i.test(error)\n || /SSL SYSCALL error: EOF detected/i.test(error)\n || /Local: Authentication failure/i.test(error)\n // https://github.com/sequelize/sequelize/pull/15144\n || error.message === 'Query read timeout'\n ) {\n connection._invalid = true;\n }\n\n error.sql = sql;\n error.parameters = parameters;\n throw this.formatError(error, errForStack.stack);\n }\n\n complete();\n\n let rows = Array.isArray(queryResult)\n ? queryResult.reduce((allRows, r) => allRows.concat(r.rows || []), [])\n : queryResult.rows;\n const rowCount = Array.isArray(queryResult)\n ? queryResult.reduce(\n (count, r) => Number.isFinite(r.rowCount) ? count + r.rowCount : count,\n 0\n )\n : queryResult.rowCount || 0;\n\n if (this.sequelize.options.minifyAliases && this.options.aliasesMapping) {\n rows = rows\n .map(row => _.toPairs(row)\n .reduce((acc, [key, value]) => {\n const mapping = this.options.aliasesMapping.get(key);\n acc[mapping || key] = value;\
|
||
|
"mappings": ";AAEA,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,aAAa,QAAQ;AAC3B,MAAM,kBAAkB,QAAQ;AAChC,MAAM,IAAI,QAAQ;AAClB,MAAM,EAAE,WAAW,QAAQ;AAE3B,MAAM,QAAQ,OAAO,aAAa;AAGlC,oBAAoB,cAAc;AAAA,SASzB,qBAAqB,KAAK,QAAQ,SAAS;AAChD,UAAM,oBAAoB,WAAS,OAAO,UAAU,WAAW,MAAM,QAAQ,OAAO,SAAS;AAE7F,QAAI;AACJ,QAAI,MAAM,QAAQ,SAAS;AACzB,kBAAY,OAA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