JavaScript: Subscribe to channel
Realtime is disabled by default for new Projects for better database performance and security. You can turn it on by managing replication .
If you want to receive the "previous" data for updates and deletes, you will need to set REPLICA IDENTITY
to FULL
, like this: ALTER TABLE your_table REPLICA IDENTITY FULL;
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()