Complete the code to subscribe to realtime updates on a table.
const subscription = supabase.channel('table_changes').on('postgres_changes', { event: 'INSERT', schema: 'public', table: '[1]' }, payload => { console.log('New row:', payload.new) }).subscribe()
The code subscribes to realtime inserts on the 'messages' table, enabling live updates when new messages arrive.
Complete the code to enable realtime on the Supabase client.
const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, { realtime: { [1]: true } })Setting 'enabled: true' inside the realtime config enables realtime features on the Supabase client.
Fix the error in the subscription code to listen for updates instead of inserts.
const subscription = supabase.channel('table_changes').on('postgres_changes', { event: '[1]', schema: 'public', table: 'messages' }, payload => { console.log('Updated row:', payload.new) }).subscribe()
To listen for updates, the event must be set to 'UPDATE'. 'INSERT' listens for new rows only.
Fill both blanks to filter realtime events for deletes on the 'orders' table in the 'sales' schema.
const subscription = supabase.channel('order_deletes').on('postgres_changes', { event: '[1]', schema: '[2]', table: 'orders' }, payload => { console.log('Deleted order:', payload.old) }).subscribe()
The event must be 'DELETE' to listen for deletions, and the schema is 'sales' as specified.
Fill all three blanks to create a realtime subscription that listens for inserts on the 'chat' table in the 'public' schema and logs the new message.
const subscription = supabase.channel('chat_inserts').on('postgres_changes', { event: '[1]', schema: '[2]', table: '[3]' }, payload => { console.log('New chat message:', payload.new) }).subscribe()
The event is 'INSERT' to listen for new rows, the schema is 'public', and the table is 'chat' as required.
