diff --git a/apps/reference/_supabase_dart/generated/getchannels.mdx b/apps/reference/_supabase_dart/generated/getchannels.mdx new file mode 100644 index 00000000000..3f01145853f --- /dev/null +++ b/apps/reference/_supabase_dart/generated/getchannels.mdx @@ -0,0 +1,23 @@ +--- +id: getchannels +title: 'getChannels()' +slug: /getchannels +custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_dart_v1_legacy.yml +--- + +import Tabs from '@theme/Tabs' +import TabItem from '@theme/TabItem' + +Returns all Realtime channels. + +```dart +final channels = supabase.getChannels(); +``` + +## Examples + +### Get all channels + +```dart +final channels = supabase.getChannels(); +``` diff --git a/apps/reference/_supabase_dart/generated/getsubscriptions.mdx b/apps/reference/_supabase_dart/generated/getsubscriptions.mdx deleted file mode 100644 index 9d7ed2989d7..00000000000 --- a/apps/reference/_supabase_dart/generated/getsubscriptions.mdx +++ /dev/null @@ -1,23 +0,0 @@ ---- -id: getsubscriptions -title: 'getSubscriptions()' -slug: /getsubscriptions -custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_dart_v1_legacy.yml ---- - -import Tabs from '@theme/Tabs' -import TabItem from '@theme/TabItem' - -Returns an array of all your subscriptions. - -```dart -final subscriptions = supabase.getSubscriptions(); -``` - -## Examples - -### Get all subscriptions - -```dart -final subscriptions = supabase.getSubscriptions(); -``` diff --git a/apps/reference/_supabase_dart/generated/removeallchannels.mdx b/apps/reference/_supabase_dart/generated/removeallchannels.mdx new file mode 100644 index 00000000000..7bfa2a276a1 --- /dev/null +++ b/apps/reference/_supabase_dart/generated/removeallchannels.mdx @@ -0,0 +1,27 @@ +--- +id: removeallchannels +title: 'removeAllChannels()' +slug: /removeallchannels +custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_dart_v1_legacy.yml +--- + +import Tabs from '@theme/Tabs' +import TabItem from '@theme/TabItem' + +Unsubscribes and removes all Realtime channels from Realtime client. + +```dart +final statuses = await supabase.removeAllChannels(); +``` + +## Notes + +- Removing channels is a great way to maintain the performance of your project's Realtime service as well as your database if you're listening to Postgres changes. Supabase will automatically handle cleanup 30 seconds after a client is disconnected, but unused channels may cause degradation as more clients are simultaneously subscribed. + +## Examples + +### Remove all channels + +```dart +final statuses = await supabase.removeAllChannels(); +``` diff --git a/apps/reference/_supabase_dart/generated/removechannel.mdx b/apps/reference/_supabase_dart/generated/removechannel.mdx new file mode 100644 index 00000000000..b0ec98929f2 --- /dev/null +++ b/apps/reference/_supabase_dart/generated/removechannel.mdx @@ -0,0 +1,27 @@ +--- +id: removechannel +title: 'removeChannel()' +slug: /removechannel +custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_dart_v1_legacy.yml +--- + +import Tabs from '@theme/Tabs' +import TabItem from '@theme/TabItem' + +Unsubscribes and removes Realtime channel from Realtime client. + +```dart +final status = await supabase.removeChannel(channel); +``` + +## Notes + +- Removing a channel is a great way to maintain the performance of your project's Realtime service as well as your database if you're listening to Postgres changes. Supabase will automatically handle cleanup 30 seconds after a client is disconnected, but unused channels may cause degradation as more clients are simultaneously subscribed. + +## Examples + +### Remove a channel + +```dart +final status = await supabase.removeChannel(channel); +``` diff --git a/apps/reference/_supabase_dart/generated/removesubscription.mdx b/apps/reference/_supabase_dart/generated/removesubscription.mdx deleted file mode 100644 index 5c95f1b1a60..00000000000 --- a/apps/reference/_supabase_dart/generated/removesubscription.mdx +++ /dev/null @@ -1,27 +0,0 @@ ---- -id: removesubscription -title: 'removeSubscription()' -slug: /removesubscription -custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_dart_v1_legacy.yml ---- - -import Tabs from '@theme/Tabs' -import TabItem from '@theme/TabItem' - -Removes an active subscription and returns the number of open connections. - -```dart -supabase.removeSubscription(mySubscription); -``` - -## Notes - -- Removing subscriptions is a great way to maintain the performance of your project's database. Supabase will automatically handle cleanup 30 seconds after a user is disconnected, but unused subscriptions may cause degradation as more users are simultaneously subscribed. - -## Examples - -### Remove a subscription - -```dart -supabase.removeSubscription(mySubscription); -``` diff --git a/apps/reference/_supabase_dart/generated/subscribe.mdx b/apps/reference/_supabase_dart/generated/subscribe.mdx index 866fed8d0ec..1bfff16bbdb 100644 --- a/apps/reference/_supabase_dart/generated/subscribe.mdx +++ b/apps/reference/_supabase_dart/generated/subscribe.mdx @@ -11,52 +11,47 @@ import TabItem from '@theme/TabItem' Subscribe to realtime changes in your database. ```dart -final mySubscription = supabase - .from('countries') - .on(SupabaseEventTypes.all, (payload) { - // Handle realtime payload - }) - .subscribe(); +supabase.channel('*').on(RealtimeListenTypes.postgresChanges, + ChannelFilter(event: '*', schema: '*'), (payload, [ref]) { + print('Change received: ${payload.toString()}'); +}).subscribe(); ``` ## Notes -- Realtime is disabled by default for new Projects for better database performance and security. You can turn it on by [managing replication](/docs/guides/api#managing-realtime). -- 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;` +- Realtime is disabled by default for new Projects for better database performance and security. You can turn it on by managing replication. +Row level security is not applied to delete statements. +- 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; +- When a delete occurs, the contents of old_record will be broadcast to all subscribers to that table so ensure that each table's replica identity only contains information that is safe to expose publicly. +- The channel name must exactly match the schema/table/filter you want to listen to separated by colons. See below examples for additional context. ## Examples ### Listen to all database changes ```dart -final mySubscription = supabase - .from('countries') - .on(SupabaseEventTypes.all, (payload) { - // Handle realtime payload - }) - .subscribe(); +supabase.channel('*').on(RealtimeListenTypes.postgresChanges, + ChannelFilter(event: '*', schema: '*'), (payload, [ref]) { + print('Change received: ${payload.toString()}'); +}).subscribe(); ``` ### Listening to a specific table ```dart -final mySubscription = supabase - .from('countries') - .on(SupabaseEventTypes.all, (payload) { - // Handle realtime payload - }) - .subscribe(); +supabase.channel('public:countries').on(RealtimeListenTypes.postgresChanges, + ChannelFilter(event: '*', schema: 'public', table: 'countries'), (payload, [ref]) { + print('Change received: ${payload.toString()}'); +}).subscribe(); ``` ### Listening to inserts ```dart -final mySubscription = supabase - .from('countries') - .on(SupabaseEventTypes.insert, (payload) { - // Handle realtime payload - }) - .subscribe(); +supabase.channel('public:countries').on(RealtimeListenTypes.postgresChanges, + ChannelFilter(event: 'INSERT', schema: 'public', table: 'countries'), (payload, [ref]) { + print('Change received: ${payload.toString()}'); +}).subscribe(); ``` ### Listening to updates @@ -69,12 +64,10 @@ alter table "your_table" replica identity full; ``` ```dart -final mySubscription = supabase - .from('countries') - .on(SupabaseEventTypes.update, (payload) { - // Handle realtime payload - }) - .subscribe(); +supabase.channel('public:countries').on(RealtimeListenTypes.postgresChanges, + ChannelFilter(event: 'UPDATE', schema: 'public', table: 'countries'), (payload, [ref]) { + print('Change received: ${payload.toString()}'); +}).subscribe(); ``` ### Listening to deletes @@ -87,12 +80,10 @@ alter table "your_table" replica identity full; ``` ```dart -final mySubscription = supabase - .from('countries') - .on(SupabaseEventTypes.delete, (payload) { - // Handle realtime payload - }) - .subscribe(); +supabase.channel('public:countries').on(RealtimeListenTypes.postgresChanges, + ChannelFilter(event: 'DELETE', schema: 'public', table: 'countries'), (payload, [ref]) { + print('Change received: ${payload.toString()}'); +}).subscribe(); ``` ### Listening to multiple events @@ -100,11 +91,15 @@ final mySubscription = supabase You can chain listeners if you want to listen to multiple events for each table. ```dart -final mySubscription = supabase - .from('countries') - .on(SupabaseEventTypes.insert, handleInsert) - .on(SupabaseEventTypes.delete, handleDelete) - .subscribe(); +supabase.channel('public:countries').on(RealtimeListenTypes.postgresChanges, + ChannelFilter(event: 'INSERT', schema: 'public', table: 'countries'), + (payload, [ref]) { + print('Change received: ${payload.toString()}'); +}).on(RealtimeListenTypes.postgresChanges, + ChannelFilter(event: 'DELETE', schema: 'public', table: 'countries'), + (payload, [ref]) { + print('Change received: ${payload.toString()}'); +}).subscribe(); ``` ### Listening to row level changes @@ -112,8 +107,14 @@ final mySubscription = supabase 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. ```dart -final mySubscription = supabase - .from('countries:id=eq.200') - .on(SupabaseEventTypes.update, handleRecordUpdated) - .subscribe(); + supabase.channel('public:countries:id=eq.200').on( + RealtimeListenTypes.postgresChanges, + ChannelFilter( + event: 'UPDATE', + schema: 'public', + table: 'countries', + filter: 'id=eq.200', + ), (payload, [ref]) { + print('Change received: ${payload.toString()}'); + }).subscribe(); ``` diff --git a/apps/reference/nav/supabase_dart_sidebars.js b/apps/reference/nav/supabase_dart_sidebars.js index dfeec03005a..b34c679d933 100644 --- a/apps/reference/nav/supabase_dart_sidebars.js +++ b/apps/reference/nav/supabase_dart_sidebars.js @@ -92,10 +92,11 @@ const sidebars = { type: 'category', label: 'Realtime', items: [ - 'generated/subscribe', - 'generated/removesubscription', - 'generated/getsubscriptions', 'generated/stream', + 'generated/subscribe', + 'generated/removechannel', + 'generated/removeallchannels', + 'generated/getchannels', ], collapsed: true, },