0

I have two tables. Table A and Table B. I am using Android with Room and Reactive Streams with ktx.

The Table A has two columns Title, Ids.
Row 1 - ['example', '1,2,3,4'].
The Table B has two columns Id, Desc. 
Row 1 - [1, 'long desc']
Row 2 - [2, 'long desc 2'].

I am using a Flowable to get the data from the database but they are two different streams.

How do I get a list of rows which are in Table B, that have the ID's in table A. Table A stores the ids of Table B as a string.

Hades
  • 3,916
  • 3
  • 34
  • 74
  • 1
    You can write an observable to get Ids from Table A and then use flatMap operator to get Observables of that Id from Table B – p.mathew13 May 17 '19 at 06:06

1 Answers1

0

I don't know detail of your use case but do you mean like this?

interface TableADao {
    fun findById(id: Long): Flowable<ItemA>
}

interface TableBDao {
    fun findByIds(ids: Array<Long>): Flowable<List<ItemB>>
}

tableADao.findById(id)
    .switchMap { itemA ->
        val ids = someLongArrayConverter(itemA.ids)
        tableBDao.findByIds(ids)
    }
    .subscribe { itemBList ->
        Log.d("result", itemBList)
    }
ytRino
  • 1,450
  • 15
  • 28