SyncQueueDao class

Data Access Object for managing sync queue items.

This DAO provides methods for querying and manipulating sync queue items in the database. It works with any database that includes the SyncQueueItems table.

Note: This is a base implementation that works without generated files. Client applications may extend this with more specific generated methods.

Constructors

SyncQueueDao(GeneratedDatabase _db)
Creates a new SyncQueueDao instance.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

deleteTask(int id) Future<int>
Deletes a specific sync queue item by its id. Returns the number of rows affected (usually 1 if successful).
deleteTasksForModelId(String modelType, String modelId) Future<int>
Deletes all pending sync tasks for a specific model type and model ID.
deleteTasksForModelIdAndOperations(String modelType, String modelId, List<String> operations) Future<int>
Deletes specific types of operations for a model ID.
findPendingSyncTask(String modelType, String modelId, String operation) Future<int?>
Find the latest pending sync queue item for a specific model operation.
findPendingSyncTaskWithNegotiation(String modelType, String modelId, String operation) Future<int?>
Find a pending sync task that's undergoing ID negotiation.
getAllItems() Future<List<Map<String, dynamic>>>
Retrieves all items from the sync queue. Returns raw data as Map<String, dynamic> since generated types are not available in the library.
getDueTasks() Future<List<Map<String, dynamic>>>
Retrieves all sync queue items that are due for processing.
getItemById(int id) Future<Map<String, dynamic>?>
Retrieves a specific sync queue item by its id. Returns null if no item with the given id is found.
getItemsByModelType(String modelType) Future<List<Map<String, dynamic>>>
Gets items by model type.
getPendingIdNegotiationItems() Future<List<Map<String, dynamic>>>
Gets all sync queue items that are pending ID negotiation.
getTasksForModelId(String modelType, String modelId) Future<List<Map<String, dynamic>>>
Finds sync queue tasks for a specific model type and model ID.
getTemporaryIds(String modelType) Future<List<Map<String, dynamic>>>
Gets all temporary IDs that need to be replaced for a given model type.
handleModelDeletion({required String modelType, required String modelId, required String payload, String? idempotencyKey, bool scheduleDelete = false, String? headers, String? extra}) Future<Map<String, dynamic>>
Smart delete logic for handling model deletion based on sync queue state.
hasOperationForModel(String modelType, String modelId, String operation) Future<bool>
Checks if a specific operation exists for a model in the sync queue.
insertItem({required String modelType, required String modelId, required String payload, required String operation, int attemptCount = 0, String? lastError, DateTime? nextRetryAt, String? idempotencyKey, String status = 'pending', String? headers, String? extra}) Future<int>
Inserts a new item into the sync queue. Returns the id of the newly inserted item.
insertItemWithIdNegotiation({required String modelType, required String modelId, required String payload, required String operation, String? temporaryClientId, String idNegotiationStatus = 'completed', int attemptCount = 0, String? lastError, DateTime? nextRetryAt, String? idempotencyKey, String status = 'pending', String? headers, String? extra}) Future<int>
Inserts an item with temporary ID tracking for server-generated IDs. This enhanced version supports ID negotiation for models that use server-generated IDs.
markIdNegotiationAsFailed({required int taskId, required String error}) Future<void>
Marks an ID negotiation as failed.
markTaskAsDead(int id, String error) Future<int>
Marks a task as 'dead' and records the final error. This prevents the task from being retried indefinitely.
modelTypeToTableName(String modelType) String
Converts model type to table name using naming convention.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
replaceIdEverywhere({required int taskId, required String oldId, required String newId, required String modelType}) Future<void>
Updates all references to an old ID with a new ID after server ID negotiation. This method must update:
toString() String
A string representation of this object.
inherited
updateItem({required int id, String? modelType, String? payload, String? operation, int? attemptCount, String? lastError, DateTime? nextRetryAt, String? idempotencyKey, String? status, String? headers, String? extra, String? idNegotiationStatus}) Future<int>
Updates an existing item in the sync queue. Returns the number of rows affected (usually 1 if successful).
updateModelSyncStatus(String modelType, String modelId, String syncStatus) Future<void>
Updates the syncStatus field in the model table.
updateTaskRetry(int id, DateTime nextRetryAt, int attemptCount, String lastError) Future<int>
Updates a task's retry information.

Operators

operator ==(Object other) bool
The equality operator.
inherited