feat: add current version of realtime

This commit is contained in:
dshukertjr committed 2022-09-07 14:57:06 +09:00
1 parent 14ee3ebe80
commit 8df4a98cf9
7 files changed
+129 -100

No files matched your search

@@ -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();
```
@@ -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();
```
@@ -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();
```
@@ -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);
```
@@ -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);
```
@@ -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();
```
+4 -3
View File
@@ -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,
},