MCPcopy
hub / github.com/sequelize/sequelize / set

Method set

src/sequelize.js:672–695  ·  view source on GitHub ↗

* Execute a query which would set an environment or user variable. The variables are set per connection, so this function needs a transaction. * Only works for MySQL or MariaDB. * * @param {object} variables Object with multiple variables. * @param {object} [options] query

(variables, options)

Source from the content-addressed store, hash-verified

670 * @returns {Promise}
671 */
672 async set(variables, options) {
673
674 // Prepare options
675 options = { ...this.options.set, ...typeof options === 'object' && options };
676
677 if (!['mysql', 'mariadb'].includes(this.options.dialect)) {
678 throw new Error('sequelize.set is only supported for mysql or mariadb');
679 }
680 if (!options.transaction || !(options.transaction instanceof Transaction) ) {
681 throw new TypeError('options.transaction is required');
682 }
683
684 // Override some options, since this isn't a SELECT
685 options.raw = true;
686 options.plain = true;
687 options.type = 'SET';
688
689 // Generate SQL Query
690 const query =
691 `SET ${
692 _.map(variables, (v, k) => `@${k} := ${typeof v === 'string' ? `"${v}"` : v}`).join(', ')}`;
693
694 return await this.query(query, options);
695 }
696
697 /**
698 * Escape value.

Callers

nothing calls this directly

Calls 1

queryMethod · 0.95

Tested by

no test coverage detected