get method

Implementation

@override
Future<InAppQuerySnapshot> get() {
  final fetchingSize = _op.fetchingSize ?? 0;
  final isQuery = _q.isNotEmpty;
  final isSorting = _o.isNotEmpty;
  final isSelections = _s.isNotEmpty;
  final isLimit = fetchingSize > 0;
  final sortingSize = _o.length;
  if (isQuery || isSorting || isSelections || isLimit) {
    return super.get().then((raw) {
      final data = raw.docs.map((e) => e.data ?? {}).toList();
      QueryBuilder builder = QueryBuilder(data);
      if (isQuery) {
        for (var i in _q) {
          builder = builder.where(
            i.field,
            isEqualTo: i.isEqualTo,
            isNotEqualTo: i.isNotEqualTo,
            isNull: i.isNull,
            isGreaterThan: i.isGreaterThan,
            isGreaterThanOrEqualTo: i.isGreaterThanOrEqualTo,
            isLessThan: i.isLessThan,
            isLessThanOrEqualTo: i.isLessThanOrEqualTo,
            whereIn: i.whereIn,
            whereNotIn: i.whereNotIn,
            arrayContains: i.arrayContains,
            arrayNotContains: i.arrayNotContains,
            arrayContainsAny: i.arrayContainsAny,
            arrayNotContainsAny: i.arrayNotContainsAny,
          );
        }
      }
      if (isSorting) {
        for (var i in _o) {
          builder = builder.orderBy(i.field, descending: i.descending);
        }
      }
      if (isSelections) {
        for (var i in _s) {
          final v = i.value;
          final vs = i.values;
          if (v is Map<String, dynamic> || vs is Iterable<Object?>) {
            final value = v is Map<String, dynamic> ? v : <String, dynamic>{};
            final values = List.from(vs ?? []);
            switch (i.type) {
              case Selections.endAt:
                builder = builder.endAt(values);
                break;
              case Selections.endAtDocument:
                builder = builder.endAtDocument(value);
                break;
              case Selections.endBefore:
                builder = builder.endBefore(values);
                break;
              case Selections.endBeforeDocument:
                builder = builder.endBeforeDocument(value);
                break;
              case Selections.startAfter:
                builder = builder.startAfter(values);
                break;
              case Selections.startAfterDocument:
                builder = builder.startAfterDocument(value);
                break;
              case Selections.startAt:
                builder = builder.startAt(values);
                break;
              case Selections.startAtDocument:
                builder = builder.startAtDocument(value);
                break;
              case Selections.none:
                break;
            }
          }
        }
      }
      if (isLimit) {
        if (_op.fetchFromLast) {
          builder = builder.limitToLast(fetchingSize);
        } else {
          builder = builder.limit(fetchingSize);
        }
      }
      return builder
          .execute(isSorting ? sortingSize * data.length : 0)
          .then((processed) {
        final docs = processed.map((e) {
          return InAppDocumentSnapshot(_id, e);
        }).toList();
        return InAppQuerySnapshot(raw.id, docs);
      });
    });
  } else {
    return super.get();
  }
}