SqlDelightTaskRepository

class SqlDelightTaskRepository(database: KmpWorkerDatabase) : TaskRepository

SQLDelight-backed implementation of TaskRepository.

All DB operations are dispatched to Dispatchers.IO to avoid blocking the main thread.

The Tasks data class is generated by SQLDelight in the same package (io.neuralheads.kmpworker.persistence), not in the .db sub-package.

Parameters

database

The SQLDelight generated database instance.

Constructors

Link copied to clipboard
constructor(database: KmpWorkerDatabase)

Functions

Link copied to clipboard
open suspend override fun delete(id: String)

Removes a task from the store. Call after TaskState.Success.

Link copied to clipboard
open suspend override fun getAll(): List<TaskRequest>

Returns all persisted tasks.

Link copied to clipboard
open suspend override fun getById(id: String): TaskRequest?

Returns a single task by ID, or null if not found.

Link copied to clipboard
open suspend override fun getPending(): List<TaskRequest>

Returns tasks with status PENDING or RUNNING. Use this on app restart to recover and re-enqueue interrupted tasks.

Link copied to clipboard
open suspend override fun insert(task: TaskRequest)

Persists a new TaskRequest with status PENDING. No-ops if a task with the same ID already exists.

Link copied to clipboard
open suspend override fun updateStatus(id: String, status: String, retryCount: Int)

Updates the status and retry count for a task.