JavaScript: Subscribe to channel

Examples

Listen to all database changes

const mySubscription = supabase
  .from('*')
  .on('*', payload => \{
    console.log('Change received!', payload)
  \})
  .subscribe()

Listen to a specific table

const mySubscription = supabase
  .from('countries')
  .on('*', payload => \{
    console.log('Change received!', payload)
  \})
  .subscribe()

Listen to inserts

const mySubscription = supabase
  .from('countries')
  .on('INSERT', payload => \{
    console.log('Change received!', payload)
  \})
  .subscribe()

Listen to updates

const mySubscription = supabase
  .from('countries')
  .on('UPDATE', payload => \{
    console.log('Change received!', payload)
  \})
  .subscribe()

Listen to deletes

const mySubscription = supabase
  .from('countries')
  .on('DELETE', payload => \{
    console.log('Change received!', payload)
  \})
  .subscribe()

Listen to multiple events

const mySubscription = supabase
  .from('countries')
  .on('INSERT', handleRecordInserted)
  .on('DELETE', handleRecordDeleted)
  .subscribe()

Listen to row level changes

const mySubscription = supabase
  .from('countries:id=eq.200')
  .on('UPDATE', handleRecordUpdated)
  .subscribe()