deleteJobsByStatus method
Deletes jobs by their status, optionally older than a specific date.
status
: The BackgroundJobStatus of jobs to delete (e.g., 'COMPLETED' or 'FAILED').olderThan
: If provided, only jobs created before this DateTime will be deleted. Returns the number of rows affected.
Implementation
Future<int> deleteJobsByStatus(
BackgroundJobStatus status, {
DateTime? olderThan,
}) async {
String query = "DELETE FROM background_service_jobs WHERE status = ?";
final params = <Object?>[status.name.toUpperCase()];
if (olderThan != null) {
query += " AND created_at < ?";
params.add(olderThan.toIso8601String());
}
final ResultSet result = await db.execute(query, params);
return result.length;
}