* 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)
| 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. |