Repository: sequelize/sequelize
File: packages/core/test/unit/sql/insert.test.js (JavaScript)

Code before:

        try {
          result = sql.insertQuery(
            User.tableName,
            { user_name: 'testuser', pass_word: '12345' },
            User.fieldRawAttributesMap,
            {
              updateOnDuplicate: ['user_name', 'pass_word', 'updated_at'],
              conflictWhere: {
                user_name: 'test where value',
              },
              upsertKeys,
            },
          );
        } catch (error) {
          result = error;
        }

        expectsql(result, {
          default: new Error(
            'missing dialect support for conflictWhere option',
          ),
          postgres:
            'INSERT INTO "users" ("user_name","pass_word") VALUES ($sequelize_1,$sequelize_2) ON CONFLICT ("user_name") WHERE "user_name" = \'test where value\' DO UPDATE SET "user_name"=EXCLUDED."user_name","pass_word"=EXCLUDED."pass_word","updated_at"=EXCLUDED."updated_at";',
          sqlite:
            'INSERT INTO `users` (`user_name`,`pass_word`) VALUES ($sequelize_1,$sequelize_2) ON CONFLICT (`user_name`) WHERE `user_name` = \'test where value\' DO UPDATE SET `user_name`=EXCLUDED.`user_name`,`pass_word`=EXCLUDED.`pass_word`,`updated_at`=EXCLUDED.`updated_at`;',
        });
      },
    );
  });

  describe('dates', () => {
    if (!dialect.supports.globalTimeZoneConfig) {
      it('rejects specifying the global timezone option', () => {
        expect(() => Support.createSequelizeInstance({ timezone: 'CET' })).to.throw('Setting a custom timezone is not supported');
      });
    } else {
      it('supports the global timezone option', () => {
        const timezoneSequelize = Support.createSequelizeInstance({
          timezone: 'CET',
        });

        const User = timezoneSequelize.define('user', {
          date: {
            type: DataTypes.DATE,
          },
        }, {
          timestamps: false,
        });

        expectsql(timezoneSequelize.dialect.queryGenerator.insertQuery(User.tableName, { date: new Date(Date.UTC(2015, 0, 20)) }, User.getAttributes(), {}),

Review comment (suggestion):
```suggestion
          'postgres sqlite':
            `INSERT INTO [users] ([user_name],[pass_word]) VALUES ($sequelize_1,$sequelize_2) ON CONFLICT ([user_name]) WHERE [user_name] = 'test where value' DO UPDATE SET [user_name]=EXCLUDED.[user_name],[pass_word]=EXCLUDED.[pass_word],[updated_at]=EXCLUDED.[updated_at];`,
```
A new change, but this is now possible

Code after:

        try {
          result = sql.insertQuery(
            User.tableName,
            { user_name: 'testuser', pass_word: '12345' },
            User.fieldRawAttributesMap,
            {
              updateOnDuplicate: ['user_name', 'pass_word', 'updated_at'],
              conflictWhere: {
                user_name: 'test where value',
              },
              upsertKeys,
            },
          );
        } catch (error) {
          result = error;
        }

        expectsql(result, {
          default: new Error(
            'missing dialect support for conflictWhere option',
          ),
          'postgres sqlite':
            `INSERT INTO [users] ([user_name],[pass_word]) VALUES ($sequelize_1,$sequelize_2) ON CONFLICT ([user_name]) WHERE [user_name] = 'test where value' DO UPDATE SET [user_name]=EXCLUDED.[user_name],[pass_word]=EXCLUDED.[pass_word],[updated_at]=EXCLUDED.[updated_at];`,
        });
      },
    );
  });

  describe('dates', () => {
    if (!dialect.supports.globalTimeZoneConfig) {
      it('rejects specifying the global timezone option', () => {
        expect(() => Support.createSequelizeInstance({ timezone: 'CET' })).to.throw('Setting a custom timezone is not supported');
      });
    } else {
      it('supports the global timezone option', () => {
        const timezoneSequelize = Support.createSequelizeInstance({
          timezone: 'CET',
        });

        const User = timezoneSequelize.define('user', {
          date: {
            type: DataTypes.DATE,
          },
        }, {
          timestamps: false,
        });

        expectsql(timezoneSequelize.dialect.queryGenerator.insertQuery(User.tableName, { date: new Date(Date.UTC(2015, 0, 20)) }, User.getAttributes(), {}),
          {
            query: {