大多数博客和堆栈建议在下面的数据库聊天。
message_table
-id
-message
-conversationId
-sender
-receiverId
conversation_table
-id
-conversationId现在message_table看起来像这样。

因此,对于聊天屏幕,我订阅了消息表。
final mySubscription = supabase
.from('message_table')
.on(SupabaseEventTypes.all, (payload) {
// Handle realtime payload
})
.subscribe();如果user1和user2在聊天,他们将从这个表中得到所有的消息。
那么,如何在supabase中使用指定的conversationId对这些数据进行过滤,以停止接收其他用户的其他消息并减少带宽?
这个数据库可行吗?
发布于 2022-09-12 06:55:43
您可以在实时侦听器上添加eq过滤器,如下所示:
支持酶-颤振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();支持酶-颤振v0.X
final subscription = supabase
.from('message_table:conversationId=eq.conv12')
.on(SupabaseEventTypes.all, (payload) {
// Handle realtime payload
})
.subscribe();您可以在官方的Supabase文档这里上阅读更多关于这个特性的信息!
发布于 2022-09-11 18:30:13
查找列满足筛选器的所有行。
var conversationId = yourvalue ;
final mySubscription = supabase
.from('message_table')
.select('message, conversationId, sender , receiverId')
.eq('conversationId', conversationId) // Correct
.on(SupabaseEventTypes.all, (payload) {
// Handle realtime payload
})
.subscribe();https://stackoverflow.com/questions/73679550
复制相似问题