compileUpsert method

  1. @override
String compileUpsert(
  1. Map<String, dynamic> query,
  2. List<Map<String, dynamic>> values,
  3. List<String> uniqueBy, [
  4. List<String>? update,
])
override

Compile an upsert statement.

Implementation

@override
String compileUpsert(
  Map<String, dynamic> query,
  List<Map<String, dynamic>> values,
  List<String> uniqueBy, [
  List<String>? update,
]) {
  final sql = compileInsertMany(query, values);

  final updateColumns = update ??
      values.first.keys.where((k) => !uniqueBy.contains(k)).toList();

  final updates = updateColumns.map((col) {
    final wrapped = wrap(col);
    return '$wrapped = VALUES($wrapped)';
  }).join(', ');

  return '$sql ON DUPLICATE KEY UPDATE $updates';
}