如何监听Supabase中parent字段为NULL的实时数据变更?
监听Supabase中parent字段为NULL的数据实时变更解决方案
你当前的过滤器写法parent IS NULL不符合Supabase Realtime的语法规则,Realtime的过滤器遵循PostgREST查询规范,判断NULL值需要使用parent=is.null的格式。
修改后的可用代码如下:
const { createClient } = require('@supabase/supabase-js') const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY, {}) // 设置自定义JWT supabase.realtime.setAuth('your-custom-jwt') const channel = supabase .channel('db-changes') .on( 'postgres_changes', { event: '*', schema: 'public', table: 'todos', filter: 'parent=is.null', }, (payload) => console.log(payload) ) .subscribe()
核心注意点
- Supabase Realtime不支持SQL原生的
IS NULL判断,必须用PostgREST规定的字段名=is.null格式来匹配NULL值。 - 确认
public.todos表的parent字段存在,且已为该表开启Realtime监听权限。
内容的提问来源于stack exchange,提问作者Sathish Kannan
相关产品推荐
相关产品推荐

