applyWhere static method
Adds a WHERE clause to a SqlStatement.
Implementation
static SqlStatement applyWhere(
SqlStatement statement,
String clause, [
List<Object?>? arguments,
]) {
// Cannot easily apply WHERE to UPSERT in this structure
if (statement.operationType == SqlOperationType.upsert) {
throw UnsupportedError('Cannot apply WHERE clause to UPSERT statement.');
}
// Cannot apply WHERE to INSERT
if (statement.operationType == SqlOperationType.insert) {
throw UnsupportedError('Cannot apply WHERE clause to INSERT statement.');
}
final newClauses = List<String>.from(statement.whereClauses)..add(clause);
// Correctly handle adding arguments using the cascade operator and addAll
final newArgs = List<Object?>.from(statement.whereArguments);
if (arguments != null) {
newArgs.addAll(arguments);
}
return statement.copyWith(
whereClauses: newClauses,
whereArguments: newArgs,
);
}