Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Further Changes to Documentation

Angelicoa95f262e9d83
diff --git a/web/docs/common/FromFunction.mdx b/web/docs/common/FromFunction.mdx
new file mode 100644
index 00000000000..ad53f4842de
--- /dev/null
+++ b/web/docs/common/FromFunction.mdx
@@ -0,0 +1,38 @@
+import Collapsable from '../../src/components/Collapsable'
+
+<!-- prettier-ignore -->
+```js {2}
+supabase
+ .from(tableName)
+```
+<div style={{display: props.verb == 'subscribe' ? 'block' : 'none'}}>
+
+#### `tableName: string`
+Name of the database table to be listened to. Using the wildcard `"*"` will lead to all tables to be listened to.
+</div>
+
+<div style={{display: props.verb == 'get' ? 'block' : 'none'}}>
+
+#### `tableName: string`
+Name of the database table that will be read from.
+</div>
+
+<div style={{display: props.verb == 'post' ? 'block' : 'none'}}>
+
+#### `tableName: string`
+Name of the database table where data will be saved.
+</div>
+
+<div style={{display: props.verb == 'patch' ? 'block' : 'none'}}>
+
+#### `tableName: string`
+Name of the database table where data will be udpated.
+</div>
+
+<div style={{display: props.verb == 'delete' ? 'block' : 'none'}}>
+
+#### `tableName: string`
+Name of the database table where data will be deleted.
+</div>
+
+---
\ No newline at end of file
diff --git a/web/docs/library/delete.mdx b/web/docs/library/delete.mdx
index a08a6c2e71f..fa806dfc6cd 100644
--- a/web/docs/library/delete.mdx
+++ b/web/docs/library/delete.mdx
@@ -8,6 +8,7 @@ import DummyData from '../common/DummyData.mdx'
import Collapsable from '../../src/components/Collapsable'
import CommonResponses from '../common/CommonResponses.mdx'
import CommonFilters from '../common/CommonFilters.mdx'
+import FromFunction from '../common/FromFunction.mdx'
We will be using these tables as reference for our examples:
@@ -48,6 +49,8 @@ const updateCountryName = async () => {
## Reference
+### `from()`
+<FromFunction verb='delete' />
### `delete()`
```js
diff --git a/web/docs/library/get.mdx b/web/docs/library/get.mdx
index b9de66fa935..a1a51a2a321 100644
--- a/web/docs/library/get.mdx
+++ b/web/docs/library/get.mdx
@@ -5,12 +5,11 @@ title: 'Reading'
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
-import DummyData from '../common/DummyData.mdx'
-// import Index from '../common/filters/Index'
import CommonFilters from '../common/CommonFilters'
import CommonResponses from '../common/CommonResponses.mdx'
-// import CommonFilters from '../common/CommonFilters.mdx'
import Collapsable from '../../src/components/Collapsable'
+import FromFunction from '../common/FromFunction.mdx'
+import DummyData from '../common/DummyData.mdx'
We will be using these tables as reference for our examples:
@@ -172,6 +171,8 @@ Calling `getCountries()` will return the following response:
## Reference
+### `from()`
+<FromFunction verb='get' />
### `get()`
diff --git a/web/docs/library/getting-started.mdx b/web/docs/library/getting-started.mdx
index e5973cc1cbb..444d7bd38ae 100755
--- a/web/docs/library/getting-started.mdx
+++ b/web/docs/library/getting-started.mdx
@@ -32,13 +32,13 @@ const supabase = createClient("https://xyzcompany.supabase.io", "1a2b-3c4d-5e6f-
createClient('supabaseURL', 'supabaseKey', OPTIONS)
```
-###### supabaseURL `:string`
+#### `supabaseURL: string`
The unique Supabase URL which is supplied when you create a new project in [your project dashboard](https://app.supabase.io).
-###### supabaseKey `:string`
+#### `supabaseKey: string`
The unique Supabase Key which is supplied when you create a new project in [your project dashboard](https://app.supabase.io).
-###### OPTIONS `:object?`
+#### `OPTIONS: object?`
```js
const options = {
diff --git a/web/docs/library/patch.mdx b/web/docs/library/patch.mdx
index e230304012e..cd8056dcc1c 100644
--- a/web/docs/library/patch.mdx
+++ b/web/docs/library/patch.mdx
@@ -8,6 +8,7 @@ import DummyData from '../common/DummyData.mdx'
import Collapsable from '../../src/components/Collapsable'
import CommonResponses from '../common/CommonResponses.mdx'
import CommonFilters from '../common/CommonFilters.mdx'
+import FromFunction from '../common/FromFunction.mdx'
We will be using these tables as reference for our examples:
@@ -48,6 +49,8 @@ const updateCountryName = async () => {
## Reference
+### `from()`
+<FromFunction verb='patch' />
### `patch()`
```js
diff --git a/web/docs/library/post.mdx b/web/docs/library/post.mdx
index fa07c944ac5..9991b9d027c 100644
--- a/web/docs/library/post.mdx
+++ b/web/docs/library/post.mdx
@@ -7,6 +7,7 @@ title: 'Creating'
import DummyData from '../common/DummyData.mdx'
import Collapsable from '../../src/components/Collapsable'
import CommonResponses from '../common/CommonResponses.mdx'
+import FromFunction from '../common/FromFunction.mdx'
We will be using these tables as reference for our examples:
@@ -79,7 +80,8 @@ const createCities = async () => {
## Reference
-
+### `from()`
+<FromFunction verb='post' />
### `post()`
```js
diff --git a/web/docs/library/subscribe.mdx b/web/docs/library/subscribe.mdx
index c2f1a57e38c..5244b5c2404 100644
--- a/web/docs/library/subscribe.mdx
+++ b/web/docs/library/subscribe.mdx
@@ -4,6 +4,7 @@ title: 'Subscribing'
---
import DummyData from '../common/DummyData.mdx'
+import FromFunction from '../common/FromFunction.mdx'
import Collapsable from '../../src/components/Collapsable'
Subscribe to realtime changes in your own database.
@@ -23,11 +24,11 @@ const supabase = createClient('https://world.supabase.io', '1a2b-3c4d-5e6f-7g8h'
// Listen to changes
const mySubscription = supabase
- .subscribe('*')
+ .from('*')
.on('*', payload => {
console.log('Change received!', payload)
})
- .connect()
+ .subscribe()
```
### Listening to a specific table
@@ -41,17 +42,17 @@ const supabase = createClient('https://world.supabase.io', '1a2b-3c4d-5e6f-7g8h'
// Listen to changes
const mySubscription = supabase
- .subscribe('countries')
+ .from('countries')
.on('*', payload => {
console.log('Change received!', payload)
})
- .connect()
+ .subscribe()
```
### Listening only to INSERTS
<!-- prettier-ignore -->
-```js {9}
+```js {9-11}
import { createClient } from '@supabase/supabase-js'
// Create a single supabase client for interacting with your database
@@ -59,17 +60,17 @@ const supabase = createClient('https://world.supabase.io', '1a2b-3c4d-5e6f-7g8h'
// Listen to changes
const mySubscription = supabase
- .subscribe('countries')
+ .from('countries')
.on('INSERT', payload => {
console.log('Change received!', payload)
})
- .connect()
+ .subscribe()
```
### Listening only to UPDATES
<!-- prettier-ignore -->
-```js {9}
+```js {9-11}
import { createClient } from '@supabase/supabase-js'
// Create a single supabase client for interacting with your database
@@ -77,17 +78,17 @@ const supabase = createClient('https://world.supabase.io', '1a2b-3c4d-5e6f-7g8h'
// Listen to changes
const mySubscription = supabase
- .subscribe('countries')
+ .from('countries')
.on('UPDATE', payload => {
console.log('Change received!', payload)
})
- .connect()
+ .subscribe()
```
### Listening only to DELETES
<!-- prettier-ignore -->
-```js {9}
+```js {9-11}
import { createClient } from '@supabase/supabase-js'
// Create a single supabase client for interacting with your database
@@ -95,11 +96,11 @@ const supabase = createClient('https://world.supabase.io', '1a2b-3c4d-5e6f-7g8h'
// Listen to changes
const mySubscription = supabase
- .subscribe('countries')
+ .from('countries')
.on('DELETE', payload => {
console.log('Change received!', payload)
})
- .connect()
+ .subscribe()
```
### Listening to multiple events
@@ -113,106 +114,123 @@ const supabase = createClient('https://world.supabase.io', '1a2b-3c4d-5e6f-7g8h'
// Listen to changes
const mySubscription = supabase
- .subscribe('countries')
+ .from('countries')
.on('INSERT', handleRecordInserted)
.on('DELETE', handleRecordDeleted)
- .connect()
+ .subscribe()
```
-### Unsubscribing
+### Removing a subscription
<!-- prettier-ignore -->
-```js {10}
+```js {15}
import { createClient } from '@supabase/supabase-js'
// Create a single supabase client for interacting with your database
const supabase = createClient('https://world.supabase.io', '1a2b-3c4d-5e6f-7g8h')
// Listen to changes
-const mySubscription = supabase.subscribe('countries')
+const mySubscription = supabase
+ .from('countries')
+ .on('*', payload => {
+ console.log('Change received!', payload)
+ })
+ .subscribe()
// Unsubscribe from changes
-supabase.unsubscribe(mySubscription)
+mySubscription.unsubscribe()
```
+### Unsubscribing
+<!-- prettier-ignore -->
+```js {15}
+import { createClient } from '@supabase/supabase-js'
+// Create a single supabase client for interacting with your database
+const supabase = createClient('https://world.supabase.io', '1a2b-3c4d-5e6f-7g8h')
-## Reference
-
-### `subscribe()`
-
-<!-- prettier-ignore -->
-```js {2}
+// Listen to changes
const mySubscription = supabase
- .subscribe('tableName')
+ .from('countries')
+ .on('*', payload => {
+ console.log('Change received!', payload)
+ })
+ .subscribe()
+
+// Disconnect mySubscription
+supabase.removeSubscription(mySubscription)
```
-###### tableName `REQUIRED`
-The database table that you want to subscribe to. Using the wildcard `"*"` will listen all tables in your database.
+## Reference
+### `from()`
-----
+<FromFunction verb='subscribe' />
### `on()`
<!-- prettier-ignore -->
```js {3}
const mySubscription = supabase
- .subscribe('tableName')
+ .from('tableName')
.on('eventType', callbackFunction)
```
-###### eventType `:string {INSERT|UPDATE|DELETE|*}`
+#### `eventType: string { "INSERT" | "UPDATE" | "DELETE" | "*" }`
The database event which you would like to receive updates for, or you can use the special wildcard `*` to listen to all changes.
-
-###### callbackFunction `:function`
+
+#### `callbackFunction: function`
A callback that will handle the payload that is sent whenever your database changes. See all Change Events below to understand all the possible payloads.
-
----
-
-### `connect()`
+### `subscribe()`
<!-- prettier-ignore -->
```js {4}
const mySubscription = supabase
- .subscribe('tableName')
- .on('eventType', callbackFunction)
- .connect()
+ .from(tableName)
+ .on(eventType, callbackFunction)
+ .subscribe()
+```
+
+Subscribes to the database table specified in `from()` and starts listening to it. An object of type *subscription* will be returned.
+
+```js {1}
+mySubscription.subscribe()
```
-Start listening to database changes.
+If the subscription already exists, but has been unsubscribed from with the function `unsubscribe()`, it can be subscribed to again through the above method.
+
----
-### `disconnect()`
+### `unsubscribe()`
<!-- prettier-ignore -->
```js {2}
mySubscription
- .disconnect()
+ .unsubscribe()
```
-Stop listening to changes. At any point you can call `connect()` on the subscription to restart the listeners.
-If you don't need to connect again in the future, use `unsubscribe()` instead.
+Stop listening to changes. At any point you can call `subscribe` on the subscription object to restart the listeners.
+If you don't need to connect again in the future, use `removeSubscription()` instead.
----
-### `unsubscribe()`
+### `removeSubscription()`
<!-- prettier-ignore -->
```js {2}
supabase
- .unsubscribe(mySubscription)
+ .removeSubscription(mySubscription)
```
Disconnects and destroys a subscription. This is the preferred method for cleaning up subscriptions which you no longer require.
-###### mySubscription `:subscription`
+#### `mySubscription: subscription`
A subscription that was previously created. If you don't have access to the subscription, you can always call `getSubscriptions()`.
-
----
### `getSubscriptions()`