Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to reload/refresh? #26

Closed
fbertuzzi opened this issue Jun 19, 2022 · 5 comments
Closed

Is there a way to reload/refresh? #26

fbertuzzi opened this issue Jun 19, 2022 · 5 comments

Comments

@fbertuzzi
Copy link

fbertuzzi commented Jun 19, 2022

Hey,

I'm currently trying to reload a @Query as my database is changed on another Process (NotificationService Extension to be exact).
I'm using a DarwinNotificationCenter as described here to notify my view.

The problem that I have now, is that I can't reload the @Query at least I don't know how to do it.
As it's not a State variable I cannot modify it. Is there maybe a builtin way in @Query or GRDB itself, which I don't know of to trigger a refresh?

@groue
Copy link
Owner

groue commented Jun 19, 2022

Hello @fbertuzzi,

The solution lies in the publisher you return from your Queryable type. For example, turn the Darwin notifications into a publisher that you use to restart the ValueObservation publisher.

And this now turns into a question about Combine more than about GRDBQuery ;-)

You should end up with something akin to:

darwinNotificationPublisher
    .map { _ in /* some ValueObservation publisher */ }
    .switchToLatest()

@fbertuzzi
Copy link
Author

Hey @groue,

Thank you for the super fast reply!
Would "restarting" the ValueObservation use the updated data in the Database File or is there more I need to do like closing and reopening the AppDatabase?

@groue
Copy link
Owner

groue commented Jun 19, 2022

Thank you for the super fast reply!

I just happened to open the lid of the computer, and there you were ;-)

Would "restarting" the ValueObservation use the updated data in the Database File or is there more I need to do like closing and reopening the AppDatabase?

You have nothing more to do: the ValueObservation will do its usual job, which is to publish the current (i.e. on disk) database value on subscription, and then wait for modifications performed in the main process. There is no cached stuff or things like that. It's really "just" a Combine puzzle.

@fbertuzzi
Copy link
Author

I just happened to open the lid of the computer, and there you were ;-)

I guess I'm pretty fortunate then!

You have nothing more to do: the ValueObservation will do its usual job, which is to publish the current (i.e. on disk) database value on subscription, and then wait for modifications performed in the main process. There is no cached stuff or things like that. It's really "just" a Combine puzzle.

Okay thats good! Shouldn't be that difficult then.
Thank you for your help!

@groue
Copy link
Owner

groue commented Jun 19, 2022

You're welcome :-) Happy GRDB!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants