getAllJobs method

Future<List<BackgroundJob>> getAllJobs({
  1. int? limit,
  2. int? offset,
})

Fetches all jobs, with optional pagination.

Implementation

Future<List<BackgroundJob>> getAllJobs({int? limit, int? offset}) async {
  String query =
      "SELECT * FROM background_service_jobs ORDER BY created_at DESC";
  final params = <Object?>[];
  if (limit != null) {
    query += " LIMIT ?";
    params.add(limit);
    if (offset != null) {
      query += " OFFSET ?";
      params.add(offset);
    }
  }
  final List<Map<String, Object?>> results = await db.getAll(query, params);
  return results.map((map) => BackgroundJob.fromMap(map)).toList();
}