I have a fairly simple database query but I can't tell what am I missing (I am just starting to learn RxJava). I'm using the mvvm architecture and my query goes something like this:
In my fragment i have a composite disposable and a click listener that triggers the code bellow.
compositeDisposable.add(
model.getDriverByName(guest.driverName!!)
.doOnSuccess { formatMessage(it.phoneNumber, guest) }
.doOnError { it.printStackTrace() }
.subscribe()
)
The method in the ViewModel looks like this:
fun getDriverByName(name: String) =
repository.getDriver(name)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
Then the parameter is passed to the repository:
fun getDriver(name: String) = guestBookDao.getDriver(name)
And this is the code for the dao:
@Query("SELECT * FROM drivers WHERE name = :name")
fun getDriver(name: String) : Single<Driver>
The expected result is for the function formatMessage() to get called but instead nothing happens, if somebody could tell me what am I missing i would be very thankful. Also i did the same query in the database inspector with the same name the function recieves and the query returns an existing user.
question from:
https://stackoverflow.com/questions/66054535/cant-obtain-a-single-from-room-database-using-rxjava 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…