pull method

  1. @override
Future<List<SyncRecord>> pull({
  1. required String collection,
  2. DateTime? since,
  3. int? limit,
  4. int? offset,
  5. SyncFilter? filter,
})
override

Pull data from backend with optional pagination and filtering

Parameters:

  • collection: Collection name to pull from
  • since: Only pull records modified after this timestamp
  • limit: Maximum number of records to pull
  • offset: 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 coll = db.collection(collection);
  SelectorBuilder query = where;
  final effectiveSince = filter?.since ?? since;
  if (effectiveSince != null) {
    query = query.gt('updated_at', effectiveSince);
  }
  var finder = coll.find(query.sortBy('updated_at'));
  if (limit != null) finder = finder.take(limit);
  if (offset != null) finder = finder.skip(offset);
  final docs = await finder.toList();
  return docs.map((doc) {
    var recordData = doc['data'] as Map<String, dynamic>;
    if (filter != null) {
      recordData = filter.applyFieldFilter(recordData);
    }
    return SyncRecord(
      recordId: doc['record_id'] as String,
      data: recordData,
      updatedAt: doc['updated_at'] as DateTime,
      version: doc['version'] as int? ?? 1,
    );
  }).toList();
}