1

StorIOSQLite has interesting method observeChangesInTable(). And When I saw it I thought that it would observe changes in given table and return list of updated items.

But it just returns updated table name. Why would I need an updated table name? I can just subscribe to hole table to be notified about an update

storIoSqLite.get()
            .listOfObjects(Item.class)
            .withQuery(
                    Query.builder()
                            .table(ItemTable.NAME)
                            .build()
            )
            .prepare()
            .asRxObservable()

Please explain what is the point of observeChangesInTable() method. And what is the best solution for my problem.

Defuera
  • 5,356
  • 3
  • 32
  • 38

1 Answers1

2

With your approach you're actually doing a query to the db and only then reacting to the change.

With StorIOSQLite.observeChangesInTable() you can react on changes in the table without doing any queries to the db. This is much much cheaper and should be used in situations when you need to do a debounce() or window(), filter() etc and only then make actual query to the db.

Hope that helps!

Artem Zinnatullin
  • 4,305
  • 1
  • 29
  • 43
  • Thanks for quick response! Do you think it's worth to open a feature request for List observeChangesInTable() method. Is it archivable with storIo? I believe this is a common need. – Defuera Apr 01 '16 at 08:54
  • What do you mean by `List observeChangesInTable()`? – Artem Zinnatullin Apr 01 '16 at 18:06
  • StorIO has `Get` operation for that which reacts on changes in db and emits query result (one of the variants is `get().listOfObjects(Some.class)` – Artem Zinnatullin Apr 03 '16 at 14:11
  • Yeah, but it always returns result for the same query. In my case there's a chat and I need to display new messages, passing each time new updatedAt argument, therefore updating the query. – Defuera Apr 04 '16 at 09:55
  • 1
    Then I'd suggest to `observeChangesInTable().flatMap(change -> get().something()`) – Artem Zinnatullin Apr 04 '16 at 16:15