--- id: subscribe title: "on().subscribe()" slug: subscribe --- import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; Subscribe to realtime changes in your databse. ```js const mySubscription = supabase .from('*') .on('*', payload => { console.log('Change received!', payload) }) .subscribe() ``` ```py # Not yet implemented ``` ## Parameters ## Notes - 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 ```js const mySubscription = supabase .from('*') .on('*', payload => { console.log('Change received!', payload) }) .subscribe() ``` ```py # Not yet implemented ``` ### Listening to a specific table ```js const mySubscription = supabase .from('countries') .on('*', payload => { console.log('Change received!', payload) }) .subscribe() ``` ```py # Not yet implemented ``` ### Listening to inserts ```js const mySubscription = supabase .from('countries') .on('INSERT', payload => { console.log('Change received!', payload) }) .subscribe() ``` ```py # Not yet implemented ``` ### Listening to updates ```js const mySubscription = supabase .from('countries') .on('UPDATE', payload => { console.log('Change received!', payload) }) .subscribe() ``` ```py # Not yet implemented ``` ### Listening to deletes ```js const mySubscription = supabase .from('countries') .on('DELETE', payload => { console.log('Change received!', payload) }) .subscribe() ``` ```py # Not yet implemented ``` ### Listening to multiple events You can chain listeners if you want to listen to multiple events for each table. ```js const mySubscription = supabase .from('countries') .on('INSERT', handleRecordInserted) .on('DELETE', handleRecordDeleted) .subscribe() ``` ```py # Not yet implemented ``` ### Listening to row level changes You can listen to individual rows using the format `{table}:{col}=eq.{val}` - where `{col}` is the column name, and `{val}` is the value which you want to match. ```js const mySubscription = supabase .from('countries:id=eq.200') .on('UPDATE', handleRecordUpdated) .subscribe() ``` ```py # Not yet implemented ```