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
14 KiB
8 lines
14 KiB
2 years ago
|
{
|
||
|
"version": 3,
|
||
|
"sources": ["../../../src/dialects/snowflake/query.js"],
|
||
|
"sourcesContent": ["'use strict';\n\nconst AbstractQuery = require('../abstract/query');\nconst sequelizeErrors = require('../../errors');\nconst _ = require('lodash');\nconst { logger } = require('../../utils/logger');\n\nconst ER_DUP_ENTRY = 1062;\nconst ER_DEADLOCK = 1213;\nconst ER_ROW_IS_REFERENCED = 1451;\nconst ER_NO_REFERENCED_ROW = 1452;\n\nconst debug = logger.debugContext('sql:snowflake');\n\nclass Query extends AbstractQuery {\n static formatBindParameters(sql, values, dialect) {\n const bindParam = [];\n const replacementFunc = (_match, key, values_) => {\n if (values_[key] !== undefined) {\n bindParam.push(values_[key]);\n return '?';\n }\n return undefined;\n };\n sql = AbstractQuery.formatBindParameters(sql, values, dialect, replacementFunc)[0];\n return [sql, bindParam.length > 0 ? bindParam : undefined];\n }\n\n async run(sql, parameters) {\n this.sql = sql;\n const { connection, options } = this;\n\n const showWarnings = this.sequelize.options.showWarnings || options.showWarnings;\n\n const complete = this._logQuery(sql, debug, parameters);\n\n if (parameters) {\n debug('parameters(%j)', parameters);\n }\n\n let results;\n\n try {\n results = await new Promise((resolve, reject) => {\n connection.execute({\n sqlText: sql,\n binds: parameters,\n complete(err, _stmt, rows) {\n if (err) {\n reject(err);\n } else {\n resolve(rows);\n }\n }\n });\n });\n } catch (error) {\n if (options.transaction && error.errno === ER_DEADLOCK) {\n try {\n await options.transaction.rollback();\n } catch (error_) {\n // ignore errors\n }\n\n options.transaction.finished = 'rollback';\n }\n\n error.sql = sql;\n error.parameters = parameters;\n throw this.formatError(error);\n } finally {\n complete();\n }\n\n if (showWarnings && results && results.warningStatus > 0) {\n await this.logWarnings(results);\n }\n return this.formatResults(results);\n }\n\n /**\n * High level function that handles the results of a query execution.\n *\n *\n * Example:\n * query.formatResults([\n * {\n * id: 1, // this is from the main table\n * attr2: 'snafu', // this is from the main table\n * Tasks.id: 1, // this is from the associated table\n * Tasks.title: 'task' // this is from the associated table\n * }\n * ])\n *\n * @param {Array} data - The result of the query execution.\n * @private\n */\n formatResults(data) {\n let result = this.instance;\n\n if (this.isInsertQuery(data)) {\n this.handleInsertQuery(data);\n\n if (!this.instance) {\n // handle bulkCreate AI primary key\n if (\n data.constructor.name === 'ResultSetHeader'\n && this.model\n && this.model.autoIncrementAttribute\n && this.model.autoIncrementAttribute === this.model.primaryKeyAttribute\n && this.model.rawAttributes[this.model.primaryKeyAttribute]\n ) {\n const startId = data[this.getInsertIdField()];\n result = [];\n for (let i = startId; i < startId + data.affectedRows; i++) {\n result.push({ [this.model.rawAttributes[this.model.primaryKeyAttribute].field]: i });\n }\n } else {\n result = data[this.getInsertIdField()];\n }\n }\n }\n\n if (this.isSelectQuery()) {\n // Snowflake will treat tables as case-insensitive, so fix the case\n // of the returned values to match attributes\n if (this.options.raw === false && this.sequelize.options.quoteIdentifiers === false) {\n const sfAttrMap = _.reduce(this.model.rawAttributes, (m, v, k) => {\n m[k.toUpperCase()] = k;\n return m;\n }, {});\n\n data = data.map(data => _.reduce(data, (prev, value, key) => {\n if ( value !== undefined &&
|
||
|
"mappings": ";AAEA,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,kBAAkB,QAAQ;AAChC,MAAM,IAAI,QAAQ;AAClB,MAAM,EAAE,WAAW,QAAQ;AAE3B,MAAM,eAAe;AACrB,MAAM,cAAc;AACpB,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAE7B,MAAM,QAAQ,OAAO,aAAa;AAElC,oBAAoB,cAAc;AAAA,SACzB,qBAAqB,KAAK,QAAQ,SAAS;AAChD,UAAM,YAAY;AAClB,UAAM,kBAAkB,CAAC,QAAQ,KAAK,YAAY;AAChD,UAAI,QAAQ,SAAS,QAAW;AAC9B,kBAAU,KAAK,QAAQ;AACvB,eAAO;AAAA;AAET,aAAO;AAAA;AAET,U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