Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
106 views
in Technique[技术] by (71.8m points)

android - Can't obtain a single from room database using RXJava

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...