How can I do a room transaction across 2 different DAOs usin rxjava?
I have this code that I would like to use with Rxjava but I need it to return some kind of observable
@Transaction
fun insertStoreWithPictures(store: Store, pictures: List<StorePicture>) {
insertStore(store)
insertPictures(pictures)
}
The store DAO
@Dao
abstract public class store {
@Insert
Single<Long> insert(store entity);
}
The storePicture DAO
@Dao
abstract public class storePicture {
@Insert
Completable insert(storePicture... entity);
}
I think you can use zip
or combine
operator of RxJava
. It would create an observable from an iterators observable source.
Best example you can follow to achieve the same - https://blog.mindorks.com/understanding-rxjava-zip-operator-with-example
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.