PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 23, 2022

[FIXED] How to queries in supabase realtime?

 October 23, 2022     dart, flutter, postgresql, sql, supabase     No comments   

Issue

Most of the blogs and stacks suggests below database for chat.

message_table
-id
-message
-conversationId
-sender
-receiverId

conversation_table
-id
-conversationId

Now message_table look like this.

enter image description here

So, for the chat screen I subscribe the message table.

final mySubscription = supabase
  .from('message_table')
  .on(SupabaseEventTypes.all, (payload) {
    // Handle realtime payload
  })
  .subscribe();

if user1 and user2 are chatting, they will get all messages from this table.

So, how to filter this data with specified conversationId in supabase to stop receive the other message of other users and for reduce of bandwidth ?

And Is this database viable ?


Solution

You can add eq filter on your realtime listeners like this:

supabase-flutter v1.X

final subscription = supabase.channel('unique_channel').on(
    RealtimeListenTypes.postgresChanges,
    ChannelFilter(
      event: '*',
      schema: 'public',
      table: 'message_table',
      filter: 'conversationId=eq.conv12',
    ), (payload, [ref]) {
      // handle realtime here
}).subscribe();

supabase-flutter v0.X

final subscription = supabase
  .from('message_table:conversationId=eq.conv12')
  .on(SupabaseEventTypes.all, (payload) {
    // Handle realtime payload
  })
  .subscribe();

You can read more about this feature on the official Supabase documentation here!



Answered By - dshukertjr
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing