upsert<T extends TableRow> method

Future<List<T>> upsert<T extends TableRow>(
  1. List<T> rows, {
  2. required List<Column> conflictColumns,
  3. List<Column>? updateColumns,
  4. Expression? updateWhere,
  5. Transaction? transaction,
  6. bool noReturn = false,
})

Upserts all TableRows in the list and returns the resulting rows. If a row conflicts on the given conflictColumns, the existing row is updated with the new values. Otherwise, a new row is inserted. This is an atomic operation.

If updateColumns is provided, only those columns will be updated on conflict. If null, all non-conflict, non-id columns are updated.

If updateWhere is provided, the update will only apply to rows matching the given expression. Rows that conflict but don't match updateWhere are skipped and not returned, so the resulting list may be shorter than rows.

If noReturn is set to true, the resulting rows are not read back from the database and an empty list is returned. This avoids the overhead of transferring and deserializing the rows when the result is not needed.

Implementation

Future<List<T>> upsert<T extends TableRow>(
  List<T> rows, {
  required List<Column> conflictColumns,
  List<Column>? updateColumns,
  Expression? updateWhere,
  Transaction? transaction,
  bool noReturn = false,
}) async {
  return _databaseConnection.upsert<T>(
    _session,
    rows,
    conflictColumns: conflictColumns,
    updateColumns: updateColumns,
    updateWhere: updateWhere,
    // ignore: invalid_use_of_visible_for_testing_member
    transaction: transaction ?? _session.transaction,
    noReturn: noReturn,
  );
}