initStream method

  1. @override
dynamic initStream({
  1. required String collectionId,
  2. required Map<String, dynamic> where,
  3. required String orderBy,
  4. bool descending = true,
  5. int? limit,
  6. bool hasPage = false,
})
override

Implementation

@override
dynamic initStream({
  required String collectionId,
  required Map<String, dynamic> where, //dynamic is QueryValue
  required String orderBy,
  bool descending = true,
  int? limit, // 페이지 크기
  bool hasPage = false,
}) {
  assert(AbsDatabase.sbDBConn != null);
  SupabaseQueryBuilder fromRef = AbsDatabase.sbDBConn!.from(collectionId);

  SupabaseStreamFilterBuilder streamBuilder = fromRef.stream(primaryKey: ['mid']);
  SupabaseStreamBuilder filterBuilder = streamBuilder;
  // where.forEach((key, value) {
  //   filterBuilder = queryMakerStream(key, value, streamBuilder);
  // });

  if (where.isNotEmpty) {
    // where 절을 하나 밖에 처리하지 못하기 때문에, 나머지는  builder 에서 제거한다.
    String key = where.keys.first;
    QueryValue value = where.values.first;

    filterBuilder = queryMakerStream(key, value, streamBuilder);

    if (limit != null) {
      return
          // fromRef
          //     .stream(primaryKey: ['mid'])
          //     .eq(key, value)
          filterBuilder.order(orderBy, ascending: !descending).limit(limit);
    }
    return
        // fromRef
        //     .stream(primaryKey: ['mid'])
        //.eq(key, value)
        filterBuilder.order(orderBy, ascending: !descending);
  }

  // where 조건절이 비어있는 경우.

  if (limit != null) {
    return
        // fromRef
        //     .stream(primaryKey: ['mid'])
        filterBuilder.order(orderBy, ascending: !descending).limit(limit);
  }
  return streamBuilder.order(orderBy, ascending: !descending);
}