square / sqlbrite

A lightweight wrapper around SQLiteOpenHelper which introduces reactive stream semantics to SQL operations.
https://square.github.io/sqlbrite/3.x/sqlbrite/
Apache License 2.0
4.57k stars 419 forks source link

how to combine two observables from database operation and return as one! #250

Closed robindanielk closed 5 years ago

robindanielk commented 6 years ago

hi...i have the following case.. POJO:

class A{
     int id;   
     List<B> b;
}

DATABASE METHODS:

public Observable<List<A>> getAList(){
    mBriteDb.createQuery(....).mapToOne(..);
}

public Observable<List<B>> getBList(int id){
    mBriteDb.createQuery(...,String.valueOf(id)).mapToOne;
}

I have a case where i need to combine both the from the above methods,

getAList()  
    .flatMapIterable(List<A>  -> a)
    .concatMap((Function<A, ObservableSource<A>) a -> {
                Integer id = a.getId();
                return Observable.fromCallable(() -> a)
                               .doOnNext(a -> {

                                    Timber.d("Thread before ZIP WITH ===>  %s", Thread.currentThread().getName());
                                })

     ===/* getVideoFileList(int videoId) returns Observable<List<VideoFiles>> */===                                  
                                 .zipWith(getBList(id)),
                                        (a1, b) -> {
                                            a1.setFiles(b);
                                            return a1;
                                        })
                                .doOnNext(vResponse -> {
                                    Timber.d("Thread After ZIP WITH ===>  %s",Thread.currentThread().getName());
                                });
                     })
                    .toList()
                    .toObservable()

     ===/* Below Print statement is not getting Executed */=================              

                    .doOnNext(a -> {
                        Timber.d("Thread after loading from the LOCAL DB ====> %s", Thread.currentThread().getName());
            });

doOnComplete and doOnNext after toList never getting executed.. Any help??

ktomek commented 6 years ago

@robindanielk read .toList() RxJava documentation -> link

robindanielk commented 6 years ago

@ktomek ..I am not sure how to make the changes in my context ..could you share a sample code!! the execution flow goes like this, flatMapIterable => toList => toObservable...statements inside the "zipWith" are then executed!!

ktomek commented 6 years ago

@robindanielk you should ask this question on stackoverflow, not here.

getBList(id) never completes and this is why after toList() nothing is emitted