Replies: 2 comments 1 reply
-
Hello @mallman, The
That's why And GRDB has no API for registering blocks of code to execute before all
As described, your use case is addressed by It's easier to use than a raw
NB: If you only care about not eventually missing any change, and coalescing is acceptable, maybe consider using |
Beta Was this translation helpful? Give feedback.
-
I made a mistake in diagnosing the problem in my app. The logic I described in my question is actually not what I'm trying to accomplish, and it's confusing matters. I'm just going to delete this discussion unless you object. I will start another one if I have a question on what I'm actually trying to achieve. This is related to #1400, but I don't want to get into that here. I'll keep the conversation about that issue in that issue. |
Beta Was this translation helpful? Give feedback.
-
I want to query my database after some changes have been made in a transaction right before the transaction is committed, and I want to do this in a
TransactionObserver
. ThedatabaseWillCommit
method seems like the right time to do this, however the documentation for that method specifies that the method must not access the database. Further, noDatabase
object is passed to this method.Why does this restriction exist? Can that API be modified to pass a
Database
instance with the restriction that it can only be used for reading?(Actually I have been reading from the database using my
DatabasePool
inTransactionObserver.databaseWillCommit
, but that is now broken for reasons I won't go into here (due to a change in my app, not due to a change in GRDB). Clearly, I need to find a solution that doesn't misuse an API or I'm going to be playing "broken API whack-a-mole".)My question derives from a particular use case in my app. In my app, I need to compute a diff to feed an
NSCollectionView.performBatchUpdates()
. I cannot assume that I've actually loaded every item at every path into the data source affected by a transaction. Therefore, I use my database as the source of truth for computing item indices, not the data source. To compute the diff forNSCollectionView.performBatchUpdates()
I need to know the index of every item inserted, removed or updated by a transaction that affects the contents of my collection view. I can get the indexes of the inserted and updated items after the transaction is committed. Clearly I cannot get the indexes of removed items after the transaction is committed. I need to get these after the transaction changes are made, but before the changes are committed. So if you have an idea for how I might accomplish this with GRDB with the current API, I would welcome a suggestion. 😄Basically, I want to emulate something like the following:
But I need to run that query at the end of any and every transaction that modifies the
DatabaseRegion
feeding my query.To put it more abstractly, I want something like
where
databaseReadCallback
is something that's defined by my transaction observer. Or, let's say, it's something like aTransactionObserver.databaseWillWillCommit(_ db: Database) throws
method.Cheers.
Beta Was this translation helpful? Give feedback.
All reactions