pushtorefresh / storio

Reactive API for SQLiteDatabase and ContentResolver.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Include notification when partially updating a record with ContentValues

ZakTaccardi opened this issue · comments

I have a Transactions table in my application. Each transaction has a "status" property, which can be like "PENDING", "CANCELLED", "COMPLETE", etc.

I wish to be able to update just the status of an existing transaction, so I use the following method:

override fun update(transactionId: String, status: TransactionStatus) {
        val contentValues = ContentValues(2)
        contentValues.put(TransactionTable.COLUMN_ID, transactionId)
        contentValues.put(TransactionTable.COLUMN_STATUS, status.toJsonString)

        storIo.lowLevel()
                .update(
                        UpdateQuery.builder()
                                .table(TransactionTable.TABLE)
                                .where(TransactionTable.COLUMN_ID + " =?")
                                .whereArgs(transactionId)
                                .build(),
                        contentValues
                )
    }

Unfortunately, using .lowLevel() does not provide observable notifications when observing the TransactionTable. see #702

Is there any way to get notifications for partial record updates? I don't want to have to get (storIo.get()) the latest record from the table just to modify 1 property (the status) and re-insert it (via storIo.put()

You've asked just at the right time!

With latest 1.13.0 release StorIO now has Notification Tags which you can add to the notification and then filter notifications by tags and perform much more granular updates.

@nikitin-da we completely forgot to add this to the documentation, can you please make a PR?

Hi, @ZakTaccardi !
In case of low level update you should send notification manually too ;)

Changes changes = Changes.newInstance("transactions");
storIo.lowLevel().notifyAboutChanges(changes);

@artem-zinnatullin done)

Closing. Feel free to reopen if lowLevel().notifyAboutChanges(changes) or tags didn't solve the problem