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
16 KiB

{
"version": 3,
"sources": ["../../../src/dialects/mariadb/query.js"],
"sourcesContent": ["'use strict';\n\nconst AbstractQuery = require('../abstract/query');\nconst sequelizeErrors = require('../../errors');\nconst _ = require('lodash');\nconst DataTypes = require('../../data-types');\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:mariadb');\n\nclass Query extends AbstractQuery {\n constructor(connection, sequelize, options) {\n super(connection, sequelize, { showWarnings: false, ...options });\n }\n\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 const errForStack = new Error();\n\n try {\n results = await connection.query(this.sql, parameters);\n } catch (error) {\n if (options.transaction && error.errno === ER_DEADLOCK) {\n // MariaDB automatically rolls-back transactions in the event of a deadlock.\n // However, we still initiate a manual rollback to ensure the connection gets released - see #13102.\n try {\n await options.transaction.rollback();\n } catch (error_) {\n // Ignore errors - since MariaDB automatically rolled back, we're\n // not that worried about this redundant rollback failing.\n }\n\n options.transaction.finished = 'rollback';\n }\n\n error.sql = sql;\n error.parameters = parameters;\n throw this.formatError(error, errForStack.stack);\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.isBulkUpdateQuery() || this.isBulkDeleteQuery()) {\n return data.affectedRows;\n }\n if (this.isUpsertQuery()) {\n return [result, data.affectedRows === 1];\n }\n if (this.isInsertQuery(data)) {\n this.handleInsertQuery(data);\n\n if (!this.instance) {\n // handle bulkCreate AI primary key\n if (\n this.model\n && this.model.autoIncrementAttribute\n && this.model.autoIncrementAttribute === this.model.primaryKeyAttribute\n && this.model.rawAttributes[this.model.primaryKeyAttribute]\n ) {\n // ONLY TRUE IF @auto_increment_increment is set to 1 !!\n // Doesn't work with GALERA => each node will reserve increment (x for first server, x+1 for next node...)\n const startId = data[this.getInsertIdField()];\n result = new Array(data.affectedRows);\n const pkField = this.model.rawAttributes[this.model.primaryKeyAttribute].field;\n for (let i = 0; i < data.affectedRows; i++) {\n result[i] = { [pkField]
"mappings": ";;;;;;;;;;;;;;;;;AAEA,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,kBAAkB,QAAQ;AAChC,MAAM,IAAI,QAAQ;AAClB,MAAM,YAAY,QAAQ;AAC1B,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,EAChC,YAAY,YAAY,WAAW,SAAS;AAC1C,UAAM,YAAY,WAAW,iBAAE,cAAc,SAAU;AAAA;AAAA,SAGlD,qBAAqB,KAAK,QAAQ,SAAS;AAChD,UAAM,YAAY;AAClB,UAAM,kBAAkB,CAAC,OAAO,KAAK,YAAY;AAC/C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