Subscribe to Views / Multiple Rows / Multiple Columns
See original GitHub issueFeature request
I would like to subscribe to a query itself, not a table. I don’t need multiple subscriptions, just one for the query. If the query changes (not always important if INSERT, UPDATE, or DELETE), I would like my observable to get updated.
Currently, we can only use this complicated subscribe
version of this query:
Promise
this.supabase.from(col).select('*').eq(field, value).single()
Subscription
this.supabase.from(${col}:${field}=eq.${value}).on('*', (payload) => {})
Is your feature request related to a problem? Please describe.
- The
eq
should be a separate method - Every other method on the promise version should be available (
gt, ls, filter, like
, etc). Views
should be available for subscriptions (NOT CLEAR AT ALL)
Describe the solution you’d like
this.supabase.from(col).select('*').eq(field, value).single()
.subscribe((snap) => {
if (snap.type === 'added') {
console.log(snap.data);
}
});
V2 is Getting MORE Complicated, and LESS Intuitive
https://supabase.com/blog/supabase-js-v2
supabaseClient
.channel('any_string_you_want')
.on(
'postgres_changes',
{
event: 'INSERT',
schema: 'public',
table: 'movies',
},
(payload) => {
console.log(payload)
}
)
.subscribe()
While the multiplayer mode looks cool, let’s complete the actual limitations of the current realtime data before moving on to more features!
- Channel names could be automatic (perhaps with UUID in the background) if we don’t want to select a channel.
- These classes and methods are MORE confusing, and don’t help basic use cases.
- This would also be useful in order to add
GraphQL Subscription
support. - I realize RLS is the biggest issue here.
- Just allowing
VIEWS
to be subscribed to would solve this problem for now.
Describe alternatives you’ve considered
I don’t think there should be an alternative. In order for it to be easy, it should work just like the regular queries, but with a subscription.
All of these Database work the exact same way in Query mode as Subscription mode, and allow complex queries (as far as the database itself can handle):
Additional context
Related: https://github.com/supabase/realtime/issues/271 https://github.com/supabase/realtime-js/issues/97 https://github.com/supabase/supabase/discussions/1206 https://github.com/supabase/realtime/issues/222 https://github.com/supabase/supabase/discussions/3193 https://github.com/supabase/supabase/discussions/3748 https://github.com/supabase/supabase/discussions/5684 https://github.com/supabase/supabase/discussions/7735
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:7 (2 by maintainers)
The
.on
and.channel
with the complex parameters where there is no documentation about options.What seems easier to understand:
1
2
I understand the broadcasting feature seems pretty cool to have. However, you have over complicated the subscription process for people who just want to subscribe to the database. I don’t know that the broadcasting feature is really important or useful to most people when you could just store items in the database directly and subscribe to that. Perhaps a good compromise would be to add another method that emulates the promise method for postgres. This perhaps would call the unintuitive method # 1 that you have created for supabase-js-v2.
In most cases, I don’t need to think about a public schema, I don’t need to think about a channel name, and I don’t need to think about an event. I want to subscribe to:
The broadcasting feature is pretty cool, but we still don’t have the NEEDED features with postgres subscriptions.
eq
filter? Firebase straight up can do more than this. A lot of your clients are moving from Firebase for the relational data support, and you can’t do relational data with real time subscriptions? a. Who decided to add theeq
clause as a random string in a filterfilter: 'body=eq.hey'
? Why? Why would you do that, especially when you just wrote a new sdk version… b. Subscriptions should not work differently than postgres promises. In fact, I suggest you separate the broadcasting from the postgres subscriptions all together, as they are two different things. This would also solve # 1. But more importantly, let’s add all the filters that promises have shall we!talking about
why subscribing toview
changes are appropriate? This is HUGE!Yes, web sockets in Supabase for the moment are very very limiting, and you guys don’t seem to have the fixes on your roadmap just yet.
Let’s change that please.
J
@jdgamble555 this is good feedback here: https://github.com/supabase/realtime-js/issues/185#issuecomment-1258851450. Will look it over and pass it on to the rest of the team. Also, what do you mean by
postgres promises
? Like the ability to perform db operations via PostgREST and get back a response on promise resolve in JS?Yes, these filters are available.
We plan to integrate this Rust worker that improves the performance of filters and will revisit adding additional filters, and/or, etc.