apply method
Returns the SQL string and the mapped parameters for this command.
Implementation
@override
(String, Map<String, Object?>) apply(P? p) {
final map = _resolveParams<P>(params, p);
final updates = <String>[];
final where = <String>[];
for (final key in map.keys) {
if (primaryKeys.contains(key)) {
where.add('$key = @$key');
continue;
}
// Skip plain nulls for patching, but allow SQL(null)
if (map[key] != null || map[key] is SQL) {
updates.add('$key = @$key');
}
}
if (updates.isEmpty) {
// Return a no-op SQL if no fields were provided for update.
return ('SELECT 1 WHERE 0', map);
}
if (where.isEmpty) {
throw ArgumentError('UpdateCommand requires at least one primary key.');
}
final sql =
'UPDATE $table SET ${updates.join(', ')} WHERE ${where.join(' AND ')}';
return (sql, map);
}