query-interface.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 sequelizeErrors = require("../../errors");
  22. const { QueryInterface } = require("../abstract/query-interface");
  23. const QueryTypes = require("../../query-types");
  24. class SnowflakeQueryInterface extends QueryInterface {
  25. async removeColumn(tableName, columnName, options) {
  26. options = options || {};
  27. const [results] = await this.sequelize.query(this.queryGenerator.getForeignKeyQuery(tableName.tableName ? tableName : {
  28. tableName,
  29. schema: this.sequelize.config.database
  30. }, columnName), __spreadValues({ raw: true }, options));
  31. if (results.length && results[0].constraint_name !== "PRIMARY") {
  32. await Promise.all(results.map((constraint) => this.sequelize.query(this.queryGenerator.dropForeignKeyQuery(tableName, constraint.constraint_name), __spreadValues({ raw: true }, options))));
  33. }
  34. return await this.sequelize.query(this.queryGenerator.removeColumnQuery(tableName, columnName), __spreadValues({ raw: true }, options));
  35. }
  36. async upsert(tableName, insertValues, updateValues, where, options) {
  37. options = __spreadValues({}, options);
  38. options.type = QueryTypes.UPSERT;
  39. options.updateOnDuplicate = Object.keys(updateValues);
  40. const model = options.model;
  41. const sql = this.queryGenerator.insertQuery(tableName, insertValues, model.rawAttributes, options);
  42. return await this.sequelize.query(sql, options);
  43. }
  44. async removeConstraint(tableName, constraintName, options) {
  45. const sql = this.queryGenerator.showConstraintsQuery(tableName.tableName ? tableName : {
  46. tableName,
  47. schema: this.sequelize.config.database
  48. }, constraintName);
  49. const constraints = await this.sequelize.query(sql, __spreadProps(__spreadValues({}, options), {
  50. type: this.sequelize.QueryTypes.SHOWCONSTRAINTS
  51. }));
  52. const constraint = constraints[0];
  53. let query;
  54. if (!constraint || !constraint.constraintType) {
  55. throw new sequelizeErrors.UnknownConstraintError({
  56. message: `Constraint ${constraintName} on table ${tableName} does not exist`,
  57. constraint: constraintName,
  58. table: tableName
  59. });
  60. }
  61. if (constraint.constraintType === "FOREIGN KEY") {
  62. query = this.queryGenerator.dropForeignKeyQuery(tableName, constraintName);
  63. } else {
  64. query = this.queryGenerator.removeIndexQuery(constraint.tableName, constraint.constraintName);
  65. }
  66. return await this.sequelize.query(query, options);
  67. }
  68. }
  69. exports.SnowflakeQueryInterface = SnowflakeQueryInterface;
  70. //# sourceMappingURL=query-interface.js.map