firstOrCreate method

Future<TRow> firstOrCreate(
  1. MssqlCondition where,
  2. TRow build()
)

Returns the first match or inserts build's row.

This two-round-trip operation needs a unique index or transaction when concurrent inserts must not race.

Implementation

Future<TRow> firstOrCreate(
  MssqlCondition where,
  TRow Function() build,
) async {
  final existing = await firstWhere(where);
  if (existing != null) return existing;
  return insert(build());
}