Listen to single row that may not exist with postgresSingleDataFlow()
#424
Replies: 1 comment 5 replies
-
So with the implementation right now this would not be possible as the initial data is fetched using the filter you provide, and then it listens on updates based on the primary key of the single value. If there is no value, it doesn't know what to use as the realtime filter. The filter used for the postgrest request is too complex for realtime thats why we need the initial data first with the primary key. What we can do is to provide an overload to provide a |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
@jan-tennert would love to get your thoughts on this:
The current implementation of
postgresSingleDataFlow()
throws an error when you try to listen to a single row that doesn't match the filters provided. What do you think about having this emit null from the flow instead of throwing an error?My use case is when viewing another user's profile, I listen to my
friendships
table to determine if the logged in user is friends with the user whose profile they're viewing. They might be friends already, in which case the row exists in the table and everything works fine, but if they aren't friends, the row doesn't exist and an error is thrown.Similarly, when a single row that's being listened to is deleted, there no longer is a row that matches the filter, and the function throws the error.
I could wrap the call in a try/catch, but then it wouldn't update if a row that did match the filter was added (if the user clicked the "add friend" button).
Would it be an option to have this emit null in the event that the row doesn't exist, and still listen for a row that matches the filter, so that the flow would update if a row that matches is created? Not sure if this is a reasonable request of the library, or if there's another way I could go about this on the client side.
Beta Was this translation helpful? Give feedback.
All reactions