updateOrCreate method

Future<TRow> updateOrCreate(
  1. MssqlCondition where,
  2. TRow build(
    1. TRow? existing
    ), {
  3. Set<String>? columns,
})

Updates the row matching where to build's, or inserts it.

The same two-round-trip caveat as firstOrCreate.

Implementation

Future<TRow> updateOrCreate(
  MssqlCondition where,
  TRow Function(TRow? existing) build, {
  Set<String>? columns,
}) async {
  final existing = await firstWhere(where);
  final row = build(existing);
  if (existing == null) return insert(row);
  await update(row, columns: columns);
  return row;
}