pull method
Future<List<SyncRecord> >
pull({
- required String collection,
- DateTime? since,
- int? limit,
- int? offset,
- SyncFilter? filter,
override
Pull data from backend with optional pagination and filtering
Parameters:
collection: Collection name to pull fromsince: Only pull records modified after this timestamplimit: Maximum number of records to pulloffset: Number of records to skip (for pagination)filter: Optional sync filter for selective synchronization
Implementation
@override
Future<List<SyncRecord>> pull({
required String collection,
DateTime? since,
int? limit,
int? offset,
SyncFilter? filter,
}) async {
final effectiveSince = filter?.since ?? since;
final effectiveLimit = filter?.limit ?? limit;
List<Map<String, dynamic>> results;
if (effectiveSince != null) {
results = await database.query(
collection,
where: 'updated_at > ?',
whereArgs: [effectiveSince.toIso8601String()],
orderBy: 'updated_at ASC',
limit: effectiveLimit,
offset: offset,
);
} else {
results = await database.query(
collection,
orderBy: 'updated_at ASC',
limit: effectiveLimit,
offset: offset,
);
}
return results.map((row) {
var recordData =
jsonDecode(row['data'] as String) as Map<String, dynamic>;
if (filter != null) recordData = filter.applyFieldFilter(recordData);
return SyncRecord(
recordId: row['record_id'] as String,
data: recordData,
updatedAt: DateTime.parse(row['updated_at'] as String),
version: row['version'] as int,
);
}).toList();
}