Commit d8687149 authored by Matthew Painter's avatar Matthew Painter Committed by Dian Fay
Browse files

fix: initialize inserts with correct onConflictUpdateExclude option

parent 4e67c3fe
Loading
Loading
Loading
Loading
+1 −1
Changes for lib/statement/insert.js: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ const Insert = function (source, record, options = {}) {
  this.stream = options.stream;
  this.onConflictIgnore = options.onConflictIgnore;
  this.onConflictUpdate = options.onConflictUpdate;
  this.onConflictUpdateExcludes = options.onConflictUpdateExcludes;
  this.onConflictUpdateExclude = options.onConflictUpdateExclude;
  this.deepInsert = Object.prototype.hasOwnProperty.call(options, 'deepInsert') && !!options.deepInsert;

  // get fields to return from options
+3 −4
Changes for test/statement/insert.js: 3 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -121,14 +121,13 @@ describe('Insert', function () {
      it('should handle onConflictUpdate option with multiple fields and conflict keys and additional excluded fields', function () {
        const result = new Insert(source, {
          field1: 'value1',
          object: 'value2',
          created_by: 'value3'
          object: 'value2'
        }, {
          onConflictUpdate: ['id', 'field2'],
          onConflictUpdateExclude: ['created_by']
          onConflictUpdateExclude: ['object']
        });

        assert.equal(result.format(), 'INSERT INTO "testsource" ("field1", "object") VALUES ($1, $2) ON CONFLICT ("id", "field2") DO UPDATE SET "field1" = EXCLUDED."field1", "object" = EXCLUDED."object" RETURNING *');
        assert.equal(result.format(), 'INSERT INTO "testsource" ("field1", "object") VALUES ($1, $2) ON CONFLICT ("id", "field2") DO UPDATE SET "field1" = EXCLUDED."field1" RETURNING *');
        assert.deepEqual(result.params, ['value1', 'value2']);
      });
    });