MCPcopy
hub / github.com/sequelize/sequelize / addConstraint

Method addConstraint

lib/dialects/abstract/query-interface.js:733–746  ·  lib/dialects/abstract/query-interface.js::QueryInterface.addConstraint

* Add a constraint to a table * * Available constraints: * - UNIQUE * - DEFAULT (MSSQL only) * - CHECK (MySQL - Ignored by the database engine ) * - FOREIGN KEY * - PRIMARY KEY * * @example <caption>UNIQUE</caption> * queryInterface.addConstraint('Users', { * field

(tableName, options)

Source from the content-addressed store, hash-verified

731 * @returns {Promise}
732 */
733 async addConstraint(tableName, options) {
734 if (!options.fields) {
735 throw new Error(class="st">'Fields must be specified through options.fields');
736 }
737
738 if (!options.type) {
739 throw new Error(class="st">'Constraint type must be specified through options.type');
740 }
741
742 options = Utils.cloneDeep(options);
743
744 const sql = this.queryGenerator.addConstraintQuery(tableName, options);
745 return await this.sequelize.query(sql, options);
746 }
747
748 async showConstraint(tableName, constraintName, options) {
749 const sql = this.queryGenerator.showConstraintsQuery(tableName, constraintName);

Callers 4

testFunction · 0.45
upsert.test.jsFile · 0.45
deferrable.test.jsFile · 0.45

Calls 2

addConstraintQueryMethod · 0.45
queryMethod · 0.45

Tested by 1

testFunction · 0.36