API Reference Source

lib/dialects/abstract/query-interface.js

  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __defProps = Object.defineProperties;
  4. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  5. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  6. var __hasOwnProp = Object.prototype.hasOwnProperty;
  7. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  8. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  9. var __spreadValues = (a, b) => {
  10. for (var prop in b || (b = {}))
  11. if (__hasOwnProp.call(b, prop))
  12. __defNormalProp(a, prop, b[prop]);
  13. if (__getOwnPropSymbols)
  14. for (var prop of __getOwnPropSymbols(b)) {
  15. if (__propIsEnum.call(b, prop))
  16. __defNormalProp(a, prop, b[prop]);
  17. }
  18. return a;
  19. };
  20. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  21. const _ = require("lodash");
  22. const Utils = require("../../utils");
  23. const DataTypes = require("../../data-types");
  24. const Transaction = require("../../transaction");
  25. const QueryTypes = require("../../query-types");
  26. class QueryInterface {
  27. constructor(sequelize, queryGenerator) {
  28. this.sequelize = sequelize;
  29. this.queryGenerator = queryGenerator;
  30. }
  31. async createDatabase(database, options) {
  32. options = options || {};
  33. const sql = this.queryGenerator.createDatabaseQuery(database, options);
  34. return await this.sequelize.query(sql, options);
  35. }
  36. async dropDatabase(database, options) {
  37. options = options || {};
  38. const sql = this.queryGenerator.dropDatabaseQuery(database);
  39. return await this.sequelize.query(sql, options);
  40. }
  41. async createSchema(schema, options) {
  42. options = options || {};
  43. const sql = this.queryGenerator.createSchema(schema);
  44. return await this.sequelize.query(sql, options);
  45. }
  46. async dropSchema(schema, options) {
  47. options = options || {};
  48. const sql = this.queryGenerator.dropSchema(schema);
  49. return await this.sequelize.query(sql, options);
  50. }
  51. async dropAllSchemas(options) {
  52. options = options || {};
  53. if (!this.queryGenerator._dialect.supports.schemas) {
  54. return this.sequelize.drop(options);
  55. }
  56. const schemas = await this.showAllSchemas(options);
  57. return Promise.all(schemas.map((schemaName) => this.dropSchema(schemaName, options)));
  58. }
  59. async showAllSchemas(options) {
  60. options = __spreadProps(__spreadValues({}, options), {
  61. raw: true,
  62. type: this.sequelize.QueryTypes.SELECT
  63. });
  64. const showSchemasSql = this.queryGenerator.showSchemasQuery(options);
  65. const schemaNames = await this.sequelize.query(showSchemasSql, options);
  66. return _.flatten(schemaNames.map((value) => value.schema_name ? value.schema_name : value));
  67. }
  68. async databaseVersion(options) {
  69. return await this.sequelize.query(this.queryGenerator.versionQuery(), __spreadProps(__spreadValues({}, options), { type: QueryTypes.VERSION }));
  70. }
  71. async createTable(tableName, attributes, options, model) {
  72. let sql = "";
  73. options = __spreadValues({}, options);
  74. if (options && options.uniqueKeys) {
  75. _.forOwn(options.uniqueKeys, (uniqueKey) => {
  76. if (uniqueKey.customIndex === void 0) {
  77. uniqueKey.customIndex = true;
  78. }
  79. });
  80. }
  81. if (model) {
  82. options.uniqueKeys = options.uniqueKeys || model.uniqueKeys;
  83. }
  84. attributes = _.mapValues(attributes, (attribute) => this.sequelize.normalizeAttribute(attribute));
  85. await this.ensureEnums(tableName, attributes, options, model);
  86. if (!tableName.schema && (options.schema || !!model && model._schema)) {
  87. tableName = this.queryGenerator.addSchema({
  88. tableName,
  89. _schema: !!model && model._schema || options.schema
  90. });
  91. }
  92. attributes = this.queryGenerator.attributesToSQL(attributes, { table: tableName, context: "createTable" });
  93. sql = this.queryGenerator.createTableQuery(tableName, attributes, options);
  94. return await this.sequelize.query(sql, options);
  95. }
  96. async dropTable(tableName, options) {
  97. options = __spreadValues({}, options);
  98. options.cascade = options.cascade || options.force || false;
  99. const sql = this.queryGenerator.dropTableQuery(tableName, options);
  100. await this.sequelize.query(sql, options);
  101. }
  102. async _dropAllTables(tableNames, skip, options) {
  103. for (const tableName of tableNames) {
  104. if (!skip.includes(tableName.tableName || tableName)) {
  105. await this.dropTable(tableName, __spreadProps(__spreadValues({}, options), { cascade: true }));
  106. }
  107. }
  108. }
  109. async dropAllTables(options) {
  110. options = options || {};
  111. const skip = options.skip || [];
  112. const tableNames = await this.showAllTables(options);
  113. const foreignKeys = await this.getForeignKeysForTables(tableNames, options);
  114. for (const tableName of tableNames) {
  115. let normalizedTableName = tableName;
  116. if (_.isObject(tableName)) {
  117. normalizedTableName = `${tableName.schema}.${tableName.tableName}`;
  118. }
  119. for (const foreignKey of foreignKeys[normalizedTableName]) {
  120. await this.sequelize.query(this.queryGenerator.dropForeignKeyQuery(tableName, foreignKey));
  121. }
  122. }
  123. await this._dropAllTables(tableNames, skip, options);
  124. }
  125. async renameTable(before, after, options) {
  126. options = options || {};
  127. const sql = this.queryGenerator.renameTableQuery(before, after);
  128. return await this.sequelize.query(sql, options);
  129. }
  130. async showAllTables(options) {
  131. options = __spreadProps(__spreadValues({}, options), {
  132. raw: true,
  133. type: QueryTypes.SHOWTABLES
  134. });
  135. const showTablesSql = this.queryGenerator.showTablesQuery(this.sequelize.config.database);
  136. const tableNames = await this.sequelize.query(showTablesSql, options);
  137. return _.flatten(tableNames);
  138. }
  139. async describeTable(tableName, options) {
  140. let schema = null;
  141. let schemaDelimiter = null;
  142. if (typeof options === "string") {
  143. schema = options;
  144. } else if (typeof options === "object" && options !== null) {
  145. schema = options.schema || null;
  146. schemaDelimiter = options.schemaDelimiter || null;
  147. }
  148. if (typeof tableName === "object" && tableName !== null) {
  149. schema = tableName.schema;
  150. tableName = tableName.tableName;
  151. }
  152. const sql = this.queryGenerator.describeTableQuery(tableName, schema, schemaDelimiter);
  153. options = __spreadProps(__spreadValues({}, options), { type: QueryTypes.DESCRIBE });
  154. try {
  155. const data = await this.sequelize.query(sql, options);
  156. if (_.isEmpty(data)) {
  157. throw new Error(`No description found for "${tableName}" table. Check the table name and schema; remember, they _are_ case sensitive.`);
  158. }
  159. return data;
  160. } catch (e) {
  161. if (e.original && e.original.code === "ER_NO_SUCH_TABLE") {
  162. throw new Error(`No description found for "${tableName}" table. Check the table name and schema; remember, they _are_ case sensitive.`);
  163. }
  164. throw e;
  165. }
  166. }
  167. async addColumn(table, key, attribute, options) {
  168. if (!table || !key || !attribute) {
  169. throw new Error("addColumn takes at least 3 arguments (table, attribute name, attribute definition)");
  170. }
  171. options = options || {};
  172. attribute = this.sequelize.normalizeAttribute(attribute);
  173. return await this.sequelize.query(this.queryGenerator.addColumnQuery(table, key, attribute), options);
  174. }
  175. async removeColumn(tableName, attributeName, options) {
  176. return this.sequelize.query(this.queryGenerator.removeColumnQuery(tableName, attributeName), options);
  177. }
  178. normalizeAttribute(dataTypeOrOptions) {
  179. let attribute;
  180. if (Object.values(DataTypes).includes(dataTypeOrOptions)) {
  181. attribute = { type: dataTypeOrOptions, allowNull: true };
  182. } else {
  183. attribute = dataTypeOrOptions;
  184. }
  185. return this.sequelize.normalizeAttribute(attribute);
  186. }
  187. quoteIdentifier(identifier2, force) {
  188. return this.queryGenerator.quoteIdentifier(identifier2, force);
  189. }
  190. quoteIdentifiers(identifiers) {
  191. return this.queryGenerator.quoteIdentifiers(identifiers);
  192. }
  193. async changeColumn(tableName, attributeName, dataTypeOrOptions, options) {
  194. options = options || {};
  195. const query = this.queryGenerator.attributesToSQL({
  196. [attributeName]: this.normalizeAttribute(dataTypeOrOptions)
  197. }, {
  198. context: "changeColumn",
  199. table: tableName
  200. });
  201. const sql = this.queryGenerator.changeColumnQuery(tableName, query);
  202. return this.sequelize.query(sql, options);
  203. }
  204. async assertTableHasColumn(tableName, columnName, options) {
  205. const description = await this.describeTable(tableName, options);
  206. if (description[columnName]) {
  207. return description;
  208. }
  209. throw new Error(`Table ${tableName} doesn't have the column ${columnName}`);
  210. }
  211. async renameColumn(tableName, attrNameBefore, attrNameAfter, options) {
  212. options = options || {};
  213. const data = (await this.assertTableHasColumn(tableName, attrNameBefore, options))[attrNameBefore];
  214. const _options = {};
  215. _options[attrNameAfter] = {
  216. attribute: attrNameAfter,
  217. type: data.type,
  218. allowNull: data.allowNull,
  219. defaultValue: data.defaultValue
  220. };
  221. if (data.defaultValue === null && !data.allowNull) {
  222. delete _options[attrNameAfter].defaultValue;
  223. }
  224. const sql = this.queryGenerator.renameColumnQuery(tableName, attrNameBefore, this.queryGenerator.attributesToSQL(_options));
  225. return await this.sequelize.query(sql, options);
  226. }
  227. async addIndex(tableName, attributes, options, rawTablename) {
  228. if (!Array.isArray(attributes)) {
  229. rawTablename = options;
  230. options = attributes;
  231. attributes = options.fields;
  232. }
  233. if (!rawTablename) {
  234. rawTablename = tableName;
  235. }
  236. options = Utils.cloneDeep(options);
  237. options.fields = attributes;
  238. const sql = this.queryGenerator.addIndexQuery(tableName, options, rawTablename);
  239. return await this.sequelize.query(sql, __spreadProps(__spreadValues({}, options), { supportsSearchPath: false }));
  240. }
  241. async showIndex(tableName, options) {
  242. const sql = this.queryGenerator.showIndexesQuery(tableName, options);
  243. return await this.sequelize.query(sql, __spreadProps(__spreadValues({}, options), { type: QueryTypes.SHOWINDEXES }));
  244. }
  245. async getForeignKeysForTables(tableNames, options) {
  246. if (tableNames.length === 0) {
  247. return {};
  248. }
  249. options = __spreadProps(__spreadValues({}, options), { type: QueryTypes.FOREIGNKEYS });
  250. const results = await Promise.all(tableNames.map((tableName) => this.sequelize.query(this.queryGenerator.getForeignKeysQuery(tableName, this.sequelize.config.database), options)));
  251. const result = {};
  252. tableNames.forEach((tableName, i) => {
  253. if (_.isObject(tableName)) {
  254. tableName = `${tableName.schema}.${tableName.tableName}`;
  255. }
  256. result[tableName] = Array.isArray(results[i]) ? results[i].map((r) => r.constraint_name) : [results[i] && results[i].constraint_name];
  257. result[tableName] = result[tableName].filter(_.identity);
  258. });
  259. return result;
  260. }
  261. async getForeignKeyReferencesForTable(tableName, options) {
  262. const queryOptions = __spreadProps(__spreadValues({}, options), {
  263. type: QueryTypes.FOREIGNKEYS
  264. });
  265. const query = this.queryGenerator.getForeignKeysQuery(tableName, this.sequelize.config.database);
  266. return this.sequelize.query(query, queryOptions);
  267. }
  268. async removeIndex(tableName, indexNameOrAttributes, options) {
  269. options = options || {};
  270. const sql = this.queryGenerator.removeIndexQuery(tableName, indexNameOrAttributes, options);
  271. return await this.sequelize.query(sql, options);
  272. }
  273. async addConstraint(tableName, options) {
  274. if (!options.fields) {
  275. throw new Error("Fields must be specified through options.fields");
  276. }
  277. if (!options.type) {
  278. throw new Error("Constraint type must be specified through options.type");
  279. }
  280. options = Utils.cloneDeep(options);
  281. const sql = this.queryGenerator.addConstraintQuery(tableName, options);
  282. return await this.sequelize.query(sql, options);
  283. }
  284. async showConstraint(tableName, constraintName, options) {
  285. const sql = this.queryGenerator.showConstraintsQuery(tableName, constraintName);
  286. return await this.sequelize.query(sql, __spreadProps(__spreadValues({}, options), { type: QueryTypes.SHOWCONSTRAINTS }));
  287. }
  288. async removeConstraint(tableName, constraintName, options) {
  289. return this.sequelize.query(this.queryGenerator.removeConstraintQuery(tableName, constraintName), options);
  290. }
  291. async insert(instance, tableName, values, options) {
  292. options = Utils.cloneDeep(options);
  293. options.hasTrigger = instance && instance.constructor.options.hasTrigger;
  294. const sql = this.queryGenerator.insertQuery(tableName, values, instance && instance.constructor.rawAttributes, options);
  295. options.type = QueryTypes.INSERT;
  296. options.instance = instance;
  297. const results = await this.sequelize.query(sql, options);
  298. if (instance)
  299. results[0].isNewRecord = false;
  300. return results;
  301. }
  302. async upsert(tableName, insertValues, updateValues, where, options) {
  303. options = __spreadValues({}, options);
  304. const model = options.model;
  305. options.type = QueryTypes.UPSERT;
  306. options.updateOnDuplicate = Object.keys(updateValues);
  307. options.upsertKeys = options.conflictFields || [];
  308. if (options.upsertKeys.length === 0) {
  309. const primaryKeys = Object.values(model.primaryKeys).map((item) => item.field);
  310. const uniqueKeys = Object.values(model.uniqueKeys).filter((c) => c.fields.length > 0).map((c) => c.fields);
  311. const indexKeys = Object.values(model._indexes).filter((c) => c.unique && c.fields.length > 0).map((c) => c.fields);
  312. for (const field of options.updateOnDuplicate) {
  313. const uniqueKey = uniqueKeys.find((fields) => fields.includes(field));
  314. if (uniqueKey) {
  315. options.upsertKeys = uniqueKey;
  316. break;
  317. }
  318. const indexKey = indexKeys.find((fields) => fields.includes(field));
  319. if (indexKey) {
  320. options.upsertKeys = indexKey;
  321. break;
  322. }
  323. }
  324. if (options.upsertKeys.length === 0 || _.intersection(options.updateOnDuplicate, primaryKeys).length) {
  325. options.upsertKeys = primaryKeys;
  326. }
  327. options.upsertKeys = _.uniq(options.upsertKeys);
  328. }
  329. const sql = this.queryGenerator.insertQuery(tableName, insertValues, model.rawAttributes, options);
  330. return await this.sequelize.query(sql, options);
  331. }
  332. async bulkInsert(tableName, records, options, attributes) {
  333. options = __spreadValues({}, options);
  334. options.type = QueryTypes.INSERT;
  335. const results = await this.sequelize.query(this.queryGenerator.bulkInsertQuery(tableName, records, options, attributes), options);
  336. return results[0];
  337. }
  338. async update(instance, tableName, values, identifier2, options) {
  339. options = __spreadValues({}, options);
  340. options.hasTrigger = instance && instance.constructor.options.hasTrigger;
  341. const sql = this.queryGenerator.updateQuery(tableName, values, identifier2, options, instance.constructor.rawAttributes);
  342. options.type = QueryTypes.UPDATE;
  343. options.instance = instance;
  344. return await this.sequelize.query(sql, options);
  345. }
  346. async bulkUpdate(tableName, values, identifier2, options, attributes) {
  347. options = Utils.cloneDeep(options);
  348. if (typeof identifier2 === "object")
  349. identifier2 = Utils.cloneDeep(identifier2);
  350. const sql = this.queryGenerator.updateQuery(tableName, values, identifier2, options, attributes);
  351. const table = _.isObject(tableName) ? tableName : { tableName };
  352. const model = _.find(this.sequelize.modelManager.models, { tableName: table.tableName });
  353. options.type = QueryTypes.BULKUPDATE;
  354. options.model = model;
  355. return await this.sequelize.query(sql, options);
  356. }
  357. async delete(instance, tableName, identifier2, options) {
  358. const cascades = [];
  359. const sql = this.queryGenerator.deleteQuery(tableName, identifier2, {}, instance.constructor);
  360. options = __spreadValues({}, options);
  361. if (!!instance.constructor && !!instance.constructor.associations) {
  362. const keys = Object.keys(instance.constructor.associations);
  363. const length = keys.length;
  364. let association;
  365. for (let i = 0; i < length; i++) {
  366. association = instance.constructor.associations[keys[i]];
  367. if (association.options && association.options.onDelete && association.options.onDelete.toLowerCase() === "cascade" && association.options.useHooks === true) {
  368. cascades.push(association.accessors.get);
  369. }
  370. }
  371. }
  372. for (const cascade of cascades) {
  373. let instances = await instance[cascade](options);
  374. if (!instances)
  375. continue;
  376. if (!Array.isArray(instances))
  377. instances = [instances];
  378. for (const _instance of instances)
  379. await _instance.destroy(options);
  380. }
  381. options.instance = instance;
  382. return await this.sequelize.query(sql, options);
  383. }
  384. async bulkDelete(tableName, where, options, model) {
  385. options = Utils.cloneDeep(options);
  386. options = _.defaults(options, { limit: null });
  387. if (options.truncate === true) {
  388. return this.sequelize.query(this.queryGenerator.truncateTableQuery(tableName, options), options);
  389. }
  390. if (typeof identifier === "object")
  391. where = Utils.cloneDeep(where);
  392. return await this.sequelize.query(this.queryGenerator.deleteQuery(tableName, where, options, model), options);
  393. }
  394. async select(model, tableName, optionsArg) {
  395. const options = __spreadProps(__spreadValues({}, optionsArg), { type: QueryTypes.SELECT, model });
  396. return await this.sequelize.query(this.queryGenerator.selectQuery(tableName, options, model), options);
  397. }
  398. async increment(model, tableName, where, incrementAmountsByField, extraAttributesToBeUpdated, options) {
  399. options = Utils.cloneDeep(options);
  400. const sql = this.queryGenerator.arithmeticQuery("+", tableName, where, incrementAmountsByField, extraAttributesToBeUpdated, options);
  401. options.type = QueryTypes.UPDATE;
  402. options.model = model;
  403. return await this.sequelize.query(sql, options);
  404. }
  405. async decrement(model, tableName, where, incrementAmountsByField, extraAttributesToBeUpdated, options) {
  406. options = Utils.cloneDeep(options);
  407. const sql = this.queryGenerator.arithmeticQuery("-", tableName, where, incrementAmountsByField, extraAttributesToBeUpdated, options);
  408. options.type = QueryTypes.UPDATE;
  409. options.model = model;
  410. return await this.sequelize.query(sql, options);
  411. }
  412. async rawSelect(tableName, options, attributeSelector, Model) {
  413. options = Utils.cloneDeep(options);
  414. options = _.defaults(options, {
  415. raw: true,
  416. plain: true,
  417. type: QueryTypes.SELECT
  418. });
  419. const sql = this.queryGenerator.selectQuery(tableName, options, Model);
  420. if (attributeSelector === void 0) {
  421. throw new Error("Please pass an attribute selector!");
  422. }
  423. const data = await this.sequelize.query(sql, options);
  424. if (!options.plain) {
  425. return data;
  426. }
  427. const result = data ? data[attributeSelector] : null;
  428. if (!options || !options.dataType) {
  429. return result;
  430. }
  431. const dataType = options.dataType;
  432. if (dataType instanceof DataTypes.DECIMAL || dataType instanceof DataTypes.FLOAT) {
  433. if (result !== null) {
  434. return parseFloat(result);
  435. }
  436. }
  437. if (dataType instanceof DataTypes.INTEGER || dataType instanceof DataTypes.BIGINT) {
  438. if (result !== null) {
  439. return parseInt(result, 10);
  440. }
  441. }
  442. if (dataType instanceof DataTypes.DATE) {
  443. if (result !== null && !(result instanceof Date)) {
  444. return new Date(result);
  445. }
  446. }
  447. return result;
  448. }
  449. async createTrigger(tableName, triggerName, timingType, fireOnArray, functionName, functionParams, optionsArray, options) {
  450. const sql = this.queryGenerator.createTrigger(tableName, triggerName, timingType, fireOnArray, functionName, functionParams, optionsArray);
  451. options = options || {};
  452. if (sql) {
  453. return await this.sequelize.query(sql, options);
  454. }
  455. }
  456. async dropTrigger(tableName, triggerName, options) {
  457. const sql = this.queryGenerator.dropTrigger(tableName, triggerName);
  458. options = options || {};
  459. if (sql) {
  460. return await this.sequelize.query(sql, options);
  461. }
  462. }
  463. async renameTrigger(tableName, oldTriggerName, newTriggerName, options) {
  464. const sql = this.queryGenerator.renameTrigger(tableName, oldTriggerName, newTriggerName);
  465. options = options || {};
  466. if (sql) {
  467. return await this.sequelize.query(sql, options);
  468. }
  469. }
  470. async createFunction(functionName, params, returnType, language, body, optionsArray, options) {
  471. const sql = this.queryGenerator.createFunction(functionName, params, returnType, language, body, optionsArray, options);
  472. options = options || {};
  473. if (sql) {
  474. return await this.sequelize.query(sql, options);
  475. }
  476. }
  477. async dropFunction(functionName, params, options) {
  478. const sql = this.queryGenerator.dropFunction(functionName, params);
  479. options = options || {};
  480. if (sql) {
  481. return await this.sequelize.query(sql, options);
  482. }
  483. }
  484. async renameFunction(oldFunctionName, params, newFunctionName, options) {
  485. const sql = this.queryGenerator.renameFunction(oldFunctionName, params, newFunctionName);
  486. options = options || {};
  487. if (sql) {
  488. return await this.sequelize.query(sql, options);
  489. }
  490. }
  491. ensureEnums() {
  492. }
  493. async setIsolationLevel(transaction, value, options) {
  494. if (!transaction || !(transaction instanceof Transaction)) {
  495. throw new Error("Unable to set isolation level for a transaction without transaction object!");
  496. }
  497. if (transaction.parent || !value) {
  498. return;
  499. }
  500. options = __spreadProps(__spreadValues({}, options), { transaction: transaction.parent || transaction });
  501. const sql = this.queryGenerator.setIsolationLevelQuery(value, {
  502. parent: transaction.parent
  503. });
  504. if (!sql)
  505. return;
  506. return await this.sequelize.query(sql, options);
  507. }
  508. async startTransaction(transaction, options) {
  509. if (!transaction || !(transaction instanceof Transaction)) {
  510. throw new Error("Unable to start a transaction without transaction object!");
  511. }
  512. options = __spreadProps(__spreadValues({}, options), { transaction: transaction.parent || transaction });
  513. options.transaction.name = transaction.parent ? transaction.name : void 0;
  514. const sql = this.queryGenerator.startTransactionQuery(transaction);
  515. return await this.sequelize.query(sql, options);
  516. }
  517. async deferConstraints(transaction, options) {
  518. options = __spreadProps(__spreadValues({}, options), { transaction: transaction.parent || transaction });
  519. const sql = this.queryGenerator.deferConstraintsQuery(options);
  520. if (sql) {
  521. return await this.sequelize.query(sql, options);
  522. }
  523. }
  524. async commitTransaction(transaction, options) {
  525. if (!transaction || !(transaction instanceof Transaction)) {
  526. throw new Error("Unable to commit a transaction without transaction object!");
  527. }
  528. if (transaction.parent) {
  529. return;
  530. }
  531. options = __spreadProps(__spreadValues({}, options), {
  532. transaction: transaction.parent || transaction,
  533. supportsSearchPath: false,
  534. completesTransaction: true
  535. });
  536. const sql = this.queryGenerator.commitTransactionQuery(transaction);
  537. const promise = this.sequelize.query(sql, options);
  538. transaction.finished = "commit";
  539. return await promise;
  540. }
  541. async rollbackTransaction(transaction, options) {
  542. if (!transaction || !(transaction instanceof Transaction)) {
  543. throw new Error("Unable to rollback a transaction without transaction object!");
  544. }
  545. options = __spreadProps(__spreadValues({}, options), {
  546. transaction: transaction.parent || transaction,
  547. supportsSearchPath: false,
  548. completesTransaction: true
  549. });
  550. options.transaction.name = transaction.parent ? transaction.name : void 0;
  551. const sql = this.queryGenerator.rollbackTransactionQuery(transaction);
  552. const promise = this.sequelize.query(sql, options);
  553. transaction.finished = "rollback";
  554. return await promise;
  555. }
  556. }
  557. exports.QueryInterface = QueryInterface;
  558. //# sourceMappingURL=query-interface.js.map