0
votes

I have select from sqlbrite db but observable do not call onComplete for some reason.

My code:

fun BriteDatabase.selectDayTimelineRecord(dayTimestamp: Long) =
createQuery(table_timeline, selectWDayRecords(dayTimestamp)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
        .mapToOneOrDefault(StatItem(dayTimestamp, 0)) { cursor -> cursor.mapTimelineStat() }

and then I try variants:

  1. working but I need to keep order so I can not use flatmap

    Observable.fromIterable(0..6).flatMap{ db.selectDayTimelineRecords(timestampOfDayInWeek(it)) }.buffer(7).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe {}

  2. not working (not delivery result but I do not know why)

    Observable.fromIterable(0..6).concatMap{ db.selectDayTimelineRecords(timestampOfDayInWeek(it)) }.buffer(7).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe {}

As result I want Observable with list of T...

Anyone know what am I doing wrong?

1

1 Answers

1
votes

I am not very familiar with SQLBrite but createQuery supposed to be keep notifying database changes. If you want to get value just once then you can use take() operator.

fun BriteDatabase.selectDayTimelineRecord(dayTimestamp: Long) =
    createQuery(table_timeline, selectWDayRecords(dayTimestamp))
        .mapToOneOrDefault(StatItem(dayTimestamp, 0)) { cursor -> cursor.mapTimelineStat() }
        .take(1)

Then your concatMap implementation will work.