DoUpdate<T extends Table, D> constructor

DoUpdate<T extends Table, D>(
  1. Insertable<D> update(
    1. T old
    ), {
  2. List<Column<Object>>? target,
  3. Expression<bool> where(
    1. T old
    )?,
  4. Expression<bool> targetCondition(
    1. T table
    )?,
})

Creates a DO UPDATE clause.

The update function will be used to construct an Insertable used to update an old row that prevented an insert. If you need to refer to both the old row and the row that would have been inserted, use DoUpdate.withExcluded.

A DO UPDATE clause must refer to a set of columns potentially causing a conflict, and only a conflict on those columns causes this clause to be applied. The most common conflict would be an existing row with the same primary key, which is the default for target. Other unique indices can be targeted too. If such a unique index has a condition, it can be set with targetCondition (which forms the rarely used WHERE in the conflict target).

The optional where clause can be used to disable the update based on the old value. If a where clause is set and it evaluates to false, a conflict will keep the old row without applying the update.

For an example, see InsertStatement.insert.

Implementation

DoUpdate(
  Insertable<D> Function(T old) update, {
  this.target,
  Expression<bool> Function(T old)? where,
  Expression<bool> Function(T table)? targetCondition,
})  : _creator = ((old, _) => update(old)),
      _where = where == null ? null : ((old, _) => Where(where(old))),
      _targetCondition = targetCondition,
      _usesExcludedTable = false;