Android Room with RxJava3

Viewed 4166

Is there a way to work with Room database with RxJava3?

the problem that when i try to return Observable or Single from Room Query it shows me the error below:

error: Not sure how to convert a Cursor to this method's return type public abstract io.reactivex.rxjava3.core.Single<java.util.List<com.osama.movieshow.data.movie.Movie>> getAllFavorites();

My Room query:

@Query("select * from favorites") fun getAllFavorites():Single<List<Movie>>

and i'm importing Single from import io.reactivex.rxjava3.core.Single

2 Answers

Room now supports Rxjava3. Use the dependency below;

implementation "androidx.room:room-rxjava3:2.3.0-alpha02"

Take a look at the RxJava bridge library [https://github.com/akarnokd/RxJavaBridge#rxjavabridge] With it, you should be able to convert rxjava2 types to rxjava3 types. It's maintained by the maintainer of RxJava.

Another thing to look out for is the jetpack release notes alpha channel [https://developer.android.com/jetpack/androidx/versions/alpha-channel?hl=en] This should list the things coming down the pipeline. Unfortunately, i don't see rxjava3 bindings for room anywhere (yet), and I don't know if Google plans to maintain that, but not a bad idea to keep an eye out.

Related