如何使用多个条件过滤Supabase Postgres CDC订阅



如何使用多个条件过滤Supabase Postgres CDC查询?

channel.on('postgres_changes', { event: 'UPDATE', schema: 'public', table: 'users', 
filter: 'username=eq.Realtime' }, (payload) => {
console.log('All updates on users table when username is Realtime: ', payload)
})

代替:filter: 'username=eq.Realtime'

我想做:filter: 'username=eq.Realtime&&firstname=neq.test'

正确的做法是什么?

目前,Supabase实时引擎只允许应用1个过滤器。在您的情况下,您只需忽略所有不符合您希望使用良好的旧if语句的条件的数据。

channel.on('postgres_changes',
{
event: 'UPDATE',
schema: 'public',
table: 'users', 
filter: 'username=eq.Realtime'
}, (payload) => {
// Check if the data meets the additional condition you would like.
if(payload.new.firstname == 'test') {
console.log('All updates on users table when username is Realtime: ', payload)
}
})

最新更新