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;
Results results;
if (effectiveSince != null) {
results = await connection.query('''
SELECT record_id, data, updated_at, version
FROM $collection
WHERE updated_at > ?
ORDER BY updated_at ASC
${effectiveLimit != null ? 'LIMIT ?' : ''}
${offset != null ? 'OFFSET ?' : ''}
''', [
effectiveSince,
if (effectiveLimit != null) effectiveLimit,
if (offset != null) offset
]);
} else {
results = await connection.query('''
SELECT record_id, data, updated_at, version
FROM $collection
ORDER BY updated_at ASC
${effectiveLimit != null ? 'LIMIT ?' : ''}
${offset != null ? 'OFFSET ?' : ''}
''', [
if (effectiveLimit != null) effectiveLimit,
if (offset != null) offset
]);
}
return results.map((row) {
var recordData = jsonDecode(row[1] as String) as Map<String, dynamic>;
if (filter != null) recordData = filter.applyFieldFilter(recordData);
return SyncRecord(
recordId: row[0] as String,
data: recordData,
updatedAt: row[2] as DateTime,
version: row[3] as int,
);
}).toList();
}