Skip to content

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

docs(reference/v2): reorder yml and sidebar

Bobbie Soedirgo95bf826fd29f
diff --git a/apps/reference/_supabase_js/generated/containedby.mdx b/apps/reference/_supabase_js/generated/containedby.mdx
index a67ce9f7428..b9b7646c7e6 100644
--- a/apps/reference/_supabase_js/generated/containedby.mdx
+++ b/apps/reference/_supabase_js/generated/containedby.mdx
@@ -1,6 +1,6 @@
---
id: containedby
-title: '.containedBy()'
+title: 'containedBy()'
slug: /containedby
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/contains.mdx b/apps/reference/_supabase_js/generated/contains.mdx
index cf9f1bd72ac..9251b9d4e1e 100644
--- a/apps/reference/_supabase_js/generated/contains.mdx
+++ b/apps/reference/_supabase_js/generated/contains.mdx
@@ -1,6 +1,6 @@
---
id: contains
-title: '.contains()'
+title: 'contains()'
slug: /contains
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/eq.mdx b/apps/reference/_supabase_js/generated/eq.mdx
index bfe7fcc4ecf..960d203882c 100644
--- a/apps/reference/_supabase_js/generated/eq.mdx
+++ b/apps/reference/_supabase_js/generated/eq.mdx
@@ -1,6 +1,6 @@
---
id: eq
-title: '.eq()'
+title: 'eq()'
slug: /eq
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/filter.mdx b/apps/reference/_supabase_js/generated/filter.mdx
index 388b86528f2..7b781898277 100644
--- a/apps/reference/_supabase_js/generated/filter.mdx
+++ b/apps/reference/_supabase_js/generated/filter.mdx
@@ -1,6 +1,6 @@
---
id: filter
-title: '.filter()'
+title: 'filter()'
slug: /filter
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/gt.mdx b/apps/reference/_supabase_js/generated/gt.mdx
index 1f9d5e09f7f..86a5640de96 100644
--- a/apps/reference/_supabase_js/generated/gt.mdx
+++ b/apps/reference/_supabase_js/generated/gt.mdx
@@ -1,6 +1,6 @@
---
id: gt
-title: '.gt()'
+title: 'gt()'
slug: /gt
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/gte.mdx b/apps/reference/_supabase_js/generated/gte.mdx
index 674285a8a85..cb4d0488e36 100644
--- a/apps/reference/_supabase_js/generated/gte.mdx
+++ b/apps/reference/_supabase_js/generated/gte.mdx
@@ -1,6 +1,6 @@
---
id: gte
-title: '.gte()'
+title: 'gte()'
slug: /gte
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/ilike.mdx b/apps/reference/_supabase_js/generated/ilike.mdx
index b2a0c5e332b..ea6cf4de817 100644
--- a/apps/reference/_supabase_js/generated/ilike.mdx
+++ b/apps/reference/_supabase_js/generated/ilike.mdx
@@ -1,6 +1,6 @@
---
id: ilike
-title: '.ilike()'
+title: 'ilike()'
slug: /ilike
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/in.mdx b/apps/reference/_supabase_js/generated/in.mdx
index 2a2e63afd45..8eddb153846 100644
--- a/apps/reference/_supabase_js/generated/in.mdx
+++ b/apps/reference/_supabase_js/generated/in.mdx
@@ -1,6 +1,6 @@
---
id: in
-title: '.in()'
+title: 'in()'
slug: /in
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/invoke.mdx b/apps/reference/_supabase_js/generated/invoke.mdx
index fb7895c1087..88339ab0d1a 100644
--- a/apps/reference/_supabase_js/generated/invoke.mdx
+++ b/apps/reference/_supabase_js/generated/invoke.mdx
@@ -8,7 +8,7 @@ custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
-Invokes a Supabase Function.
+Invoke a Supabase Function.
```js
const { data: user, error } = await supabase.functions.invoke('hello', {
diff --git a/apps/reference/_supabase_js/generated/is.mdx b/apps/reference/_supabase_js/generated/is.mdx
index 2d3cf423079..a1323e7565d 100644
--- a/apps/reference/_supabase_js/generated/is.mdx
+++ b/apps/reference/_supabase_js/generated/is.mdx
@@ -1,6 +1,6 @@
---
id: is
-title: '.is()'
+title: 'is()'
slug: /is
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/like.mdx b/apps/reference/_supabase_js/generated/like.mdx
index 279c21dbfb0..4fd8987a65a 100644
--- a/apps/reference/_supabase_js/generated/like.mdx
+++ b/apps/reference/_supabase_js/generated/like.mdx
@@ -1,6 +1,6 @@
---
id: like
-title: '.like()'
+title: 'like()'
slug: /like
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/lt.mdx b/apps/reference/_supabase_js/generated/lt.mdx
index 06e9e17587f..b3a79165666 100644
--- a/apps/reference/_supabase_js/generated/lt.mdx
+++ b/apps/reference/_supabase_js/generated/lt.mdx
@@ -1,6 +1,6 @@
---
id: lt
-title: '.lt()'
+title: 'lt()'
slug: /lt
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/lte.mdx b/apps/reference/_supabase_js/generated/lte.mdx
index 8d0aa520815..0c5fff4336c 100644
--- a/apps/reference/_supabase_js/generated/lte.mdx
+++ b/apps/reference/_supabase_js/generated/lte.mdx
@@ -1,6 +1,6 @@
---
id: lte
-title: '.lte()'
+title: 'lte()'
slug: /lte
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/match.mdx b/apps/reference/_supabase_js/generated/match.mdx
index e814d63ba8b..11fcc31e0a0 100644
--- a/apps/reference/_supabase_js/generated/match.mdx
+++ b/apps/reference/_supabase_js/generated/match.mdx
@@ -1,6 +1,6 @@
---
id: match
-title: '.match()'
+title: 'match()'
slug: /match
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/neq.mdx b/apps/reference/_supabase_js/generated/neq.mdx
index 99cdad88837..9b65ed8cc39 100644
--- a/apps/reference/_supabase_js/generated/neq.mdx
+++ b/apps/reference/_supabase_js/generated/neq.mdx
@@ -1,6 +1,6 @@
---
id: neq
-title: '.neq()'
+title: 'neq()'
slug: /neq
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/not.mdx b/apps/reference/_supabase_js/generated/not.mdx
index 6d0acddaf52..d72667d25c8 100644
--- a/apps/reference/_supabase_js/generated/not.mdx
+++ b/apps/reference/_supabase_js/generated/not.mdx
@@ -1,6 +1,6 @@
---
id: not
-title: '.not()'
+title: 'not()'
slug: /not
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/or.mdx b/apps/reference/_supabase_js/generated/or.mdx
index c71a3e65727..a679144ae54 100644
--- a/apps/reference/_supabase_js/generated/or.mdx
+++ b/apps/reference/_supabase_js/generated/or.mdx
@@ -1,6 +1,6 @@
---
id: or
-title: '.or()'
+title: 'or()'
slug: /or
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/overlaps.mdx b/apps/reference/_supabase_js/generated/overlaps.mdx
index 230a3e74343..1555fd0a48a 100644
--- a/apps/reference/_supabase_js/generated/overlaps.mdx
+++ b/apps/reference/_supabase_js/generated/overlaps.mdx
@@ -1,6 +1,6 @@
---
id: overlaps
-title: '.overlaps()'
+title: 'overlaps()'
slug: /overlaps
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/rangeadjacent.mdx b/apps/reference/_supabase_js/generated/rangeadjacent.mdx
index 68354ef9c71..b914235562e 100644
--- a/apps/reference/_supabase_js/generated/rangeadjacent.mdx
+++ b/apps/reference/_supabase_js/generated/rangeadjacent.mdx
@@ -1,6 +1,6 @@
---
id: rangeadjacent
-title: '.rangeAdjacent()'
+title: 'rangeAdjacent()'
slug: /rangeadjacent
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/rangegt.mdx b/apps/reference/_supabase_js/generated/rangegt.mdx
index 7e83b481a63..fec4709eb04 100644
--- a/apps/reference/_supabase_js/generated/rangegt.mdx
+++ b/apps/reference/_supabase_js/generated/rangegt.mdx
@@ -1,6 +1,6 @@
---
id: rangegt
-title: '.rangeGt()'
+title: 'rangeGt()'
slug: /rangegt
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/rangegte.mdx b/apps/reference/_supabase_js/generated/rangegte.mdx
index 0db21b6b434..d2b34265774 100644
--- a/apps/reference/_supabase_js/generated/rangegte.mdx
+++ b/apps/reference/_supabase_js/generated/rangegte.mdx
@@ -1,6 +1,6 @@
---
id: rangegte
-title: '.rangeGte()'
+title: 'rangeGte()'
slug: /rangegte
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/rangelt.mdx b/apps/reference/_supabase_js/generated/rangelt.mdx
index 9137e1f8ac7..6cc7d3333d8 100644
--- a/apps/reference/_supabase_js/generated/rangelt.mdx
+++ b/apps/reference/_supabase_js/generated/rangelt.mdx
@@ -1,6 +1,6 @@
---
id: rangelt
-title: '.rangeLt()'
+title: 'rangeLt()'
slug: /rangelt
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/rangelte.mdx b/apps/reference/_supabase_js/generated/rangelte.mdx
index f45c374282c..10c1ec3d288 100644
--- a/apps/reference/_supabase_js/generated/rangelte.mdx
+++ b/apps/reference/_supabase_js/generated/rangelte.mdx
@@ -1,6 +1,6 @@
---
id: rangelte
-title: '.rangeLte()'
+title: 'rangeLte()'
slug: /rangelte
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/_supabase_js/generated/textsearch.mdx b/apps/reference/_supabase_js/generated/textsearch.mdx
index d26d6b4a31b..f7facded25a 100644
--- a/apps/reference/_supabase_js/generated/textsearch.mdx
+++ b/apps/reference/_supabase_js/generated/textsearch.mdx
@@ -1,6 +1,6 @@
---
id: textsearch
-title: '.textSearch()'
+title: 'textSearch()'
slug: /textsearch
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
diff --git a/apps/reference/nav/supabase_js_sidebars.js b/apps/reference/nav/supabase_js_sidebars.js
index dc9d9f70f4e..d4f60a2ff10 100644
--- a/apps/reference/nav/supabase_js_sidebars.js
+++ b/apps/reference/nav/supabase_js_sidebars.js
@@ -63,12 +63,6 @@ const sidebars = {
],
collapsed: true,
},
- {
- type: 'category',
- label: 'Functions',
- items: ['generated/invoke'],
- collapsed: true,
- },
{
type: 'category',
label: 'Database',
@@ -79,27 +73,11 @@ const sidebars = {
'generated/upsert',
'generated/delete',
'generated/rpc',
- {
- type: 'category',
- label: 'Modifiers',
- items: [
- 'generated/using-modifiers',
- 'generated/limit',
- 'generated/order',
- 'generated/range',
- 'generated/single',
- 'generated/maybesingle',
- ],
- collapsed: true,
- },
{
type: 'category',
label: 'Filters',
items: [
'generated/using-filters',
- 'generated/or',
- 'generated/not',
- 'generated/match',
'generated/eq',
'generated/neq',
'generated/gt',
@@ -112,20 +90,42 @@ const sidebars = {
'generated/in',
'generated/contains',
'generated/containedby',
- 'generated/rangelt',
'generated/rangegt',
'generated/rangegte',
+ 'generated/rangelt',
'generated/rangelte',
'generated/rangeadjacent',
'generated/overlaps',
'generated/textsearch',
+ 'generated/match',
+ 'generated/not',
+ 'generated/or',
'generated/filter',
],
collapsed: true,
},
+ {
+ type: 'category',
+ label: 'Modifiers',
+ items: [
+ 'generated/using-modifiers',
+ 'generated/order',
+ 'generated/limit',
+ 'generated/range',
+ 'generated/single',
+ 'generated/maybesingle',
+ ],
+ collapsed: true,
+ },
],
collapsed: true,
},
+ {
+ type: 'category',
+ label: 'Functions',
+ items: ['generated/invoke'],
+ collapsed: true,
+ },
{
type: 'category',
label: 'Realtime',
diff --git a/spec/supabase_js_v2_legacy.yml b/spec/supabase_js_v2_legacy.yml
index d9efbf6140f..69a255e32d1 100644
--- a/spec/supabase_js_v2_legacy.yml
+++ b/spec/supabase_js_v2_legacy.yml
@@ -635,62 +635,6 @@ pages:
{ phone_confirm: true }
)
```
- invoke():
- title: 'invoke()'
- description: |
- Invokes a Supabase Function.
- $ref: '@supabase/functions-js.index.FunctionsClient.invoke'
- notes: |
- - Requires an Authorization header.
- - Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec.
- - When you pass in a body to your function, we automatically attach the Content-Type header for `Blob`, `ArrayBuffer`, `File`, `FormData` and `String`. If it doesn't match any of these types we assume the payload is `json`, serialise it and attach the `Content-Type` header as `application/json`. You can override this behaviour by passing in a `Content-Type` header of your own.
- - Responses are automatically parsed as `json`, `blob` and `form-data` depending on the `Content-Type` header sent by your function. Responses are parsed as `text` by default.
- examples:
- - name: Basic invocation.
- description:
- isSpotlight: true
- js: |
- ```js
- const { data: user, error } = await supabase.functions.invoke('hello', {
- body: { foo: 'bar' }
- })
- ```
- - name: Error handling.
- description: |
- A `FunctionsHttpError` error is returned if your function throws an error, `FunctionsRelayError` if the Supabase Relay has an error processing your function and `FunctionsFetchError` if there is a network error in calling your function.
- isSpotlight: true
- js: |
- ```js
- import { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError } from "@supabase/supabase-js";
-
- const { data: user, error } = await supabase.functions.invoke('hello', {
- headers: {
- "my-custom-header": 'my-custom-header-value'
- },
- body: { foo: 'bar' }
- })
-
- if (error instanceof FunctionsHttpError) {
- console.log('Function returned an error', error.message)
- } else if (error instanceof FunctionsRelayError) {
- console.log('Relay error:', error.message)
- } else if (error instanceof FunctionsFetchError) {
- console.log('Fetch error:', error.message)
- }
- ```
- - name: Passing custom headers.
- description: |
- You can pass custom headers to your function. Note: supabase-js automatically passes the `Authorization` header with the signed in user's JWT.
- isSpotlight: true
- js: |
- ```js
- const { data: user, error } = await supabase.functions.invoke('hello', {
- headers: {
- "my-custom-header": 'my-custom-header-value'
- },
- body: { foo: 'bar' }
- })
- ```
select():
title: 'Fetch data: select()'
@@ -1031,519 +975,358 @@ pages:
.rpc('hello_world', {}, { count: 'exact' })
```
- subscribe():
- title: 'on().subscribe()'
- $ref: '@supabase/realtime-js.RealtimeChannel.on'
- 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).
- - 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.
+ Using Filters:
+ description: |
+ Filters can be used on `select()`, `update()`, and `delete()` queries.
+
+ If a Postgres function returns a table response, you can also apply filters.
+
+ ### Applying Filters
+
+ You must apply your filters to the end of your query. For example:
+
+ ```js
+ const { data, error } = await supabase
+ .from('cities')
+ .select('name, country_id')
+ .eq('name', 'The Shire') // Correct
+
+ const { data, error } = await supabase
+ .from('cities')
+ .eq('name', 'The Shire') // Incorrect
+ .select('name, country_id')
+ ```
+
+ ### Chaining
+
+ Filters can be chained together to produce advanced queries. For example:
+
+ ```js
+ const { data, error } = await supabase
+ .from('cities')
+ .select('name, country_id')
+ .gte('population', 1000)
+ .lt('population', 10000)
+ ```
+
+ ### Conditional Chaining
+
+ Filters can be built up one step at a time and then executed. For example:
+
+ ```js
+ const filterByName = null
+ const filterPopLow = 1000
+ const filterPopHigh = 10000
+
+ let query = supabase
+ .from('cities')
+ .select('name, country_id')
+
+ if (filterByName) { query = query.eq('name', filterByName) }
+ if (filterPopLow) { query = query.gte('population', filterPopLow) }
+ if (filterPopHigh) { query = query.lt('population', filterPopHigh) }
+
+ const { data, error } = await query
+ ```
+
+ eq():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.eq'
examples:
- - name: Listen to all database changes
+ - name: With `select()`
isSpotlight: true
js: |
```js
- supabase
- .channel('*')
- .on('postgres_changes', { event: '*', schema: '*' }, payload => {
- console.log('Change received!', payload)
- })
- .subscribe()
+ const { data, error } = await supabase
+ .from('cities')
+ .select('name, country_id')
+ .eq('name', 'The shire')
```
- - name: Listening to a specific table
+ - name: With `update()`
js: |
```js
- supabase
- .channel('public:countries')
- .on('postgres_changes', { event: '*', schema: 'public', table: 'countries' }, payload => {
- console.log('Change received!', payload)
- })
- .subscribe()
+ const { data, error } = await supabase
+ .from('cities')
+ .update({ name: 'Mordor' })
+ .eq('name', 'San Francisco')
```
- - name: Listening to inserts
+ - name: With `delete()`
js: |
```js
- supabase
- .channel('public:countries')
- .on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'countries' }, payload => {
- console.log('Change received!', payload)
- })
- .subscribe()
- ```
- - name: Listening to updates
- description: |
- By default, Supabase will send only the updated record. If you want to receive the previous values as well you can
- enable full replication for the table you are listening to:
-
- ```sql
- alter table "your_table" replica identity full;
+ const { data, error } = await supabase
+ .from('cities')
+ .delete()
+ .eq('name', 'Mordor')
```
+ - name: With `rpc()`
js: |
```js
- supabase
- .channel('public:countries')
- .on('postgres_changes', { event: 'UPDATE', schema: 'public', table: 'countries' }, payload => {
- console.log('Change received!', payload)
- })
- .subscribe()
+ // Only valid if the Postgres function returns a table type.
+ const { data, error } = await supabase
+ .rpc('echo_all_cities')
+ .eq('name', 'San Francisco')
```
- - name: Listening to deletes
- description: |
- By default, Supabase does not send deleted records. If you want to receive the deleted record you can
- enable full replication for the table you are listening too:
- ```sql
- alter table "your_table" replica identity full;
- ```
+ neq():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.neq'
+ examples:
+ - name: With `select()`
+ isSpotlight: true
js: |
```js
- supabase
- .channel('public:countries')
- .on('postgres_changes', { event: 'DELETE', schema: 'public', table: 'countries' }, payload => {
- console.log('Change received!', payload)
- })
- .subscribe()
+ const { data, error } = await supabase
+ .from('cities')
+ .select('name, country_id')
+ .neq('name', 'The shire')
```
- - name: Listening to multiple events
- description: You can chain listeners if you want to listen to multiple events for each table.
+ - name: With `update()`
js: |
```js
- supabase
- .channel('public:countries')
- .on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'countries' }, handleRecordInserted)
- .on('postgres_changes', { event: 'DELETE', schema: 'public', table: 'countries' }, handleRecordDeleted)
- .subscribe()
+ const { data, error } = await supabase
+ .from('cities')
+ .update({ name: 'Mordor' })
+ .neq('name', 'San Francisco')
```
- - name: Listening to row level changes
- description: 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.
- notes: |
- - ``eq`` filter works with all database types as under the hood, it's casting both the filter value and the database value to the correct type and then comparing them.
+ - name: With `delete()`
js: |
```js
- supabase
- .channel('public:countries:id=eq.200')
- .on('postgres_changes', { event: 'UPDATE', schema: 'public', table: 'countries', filter: 'id=eq.200' }, handleRecordUpdated)
- .subscribe()
+ const { data, error } = await supabase
+ .from('cities')
+ .delete()
+ .neq('name', 'Mordor')
```
-
- removeChannel():
- title: 'removeChannel()'
- $ref: '@supabase/supabase-js.index.SupabaseClient.removeChannel'
- 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:
- - name: Removes a channel
- isSpotlight: true
+ - name: With `rpc()`
js: |
```js
- supabase.removeChannel(myChannel)
+ // Only valid if the Postgres function returns a table type.
+ const { data, error } = await supabase
+ .rpc('echo_all_cities')
+ .neq('name', 'Lagos')
```
- removeAllChannels():
- title: 'removeAllChannels()'
- $ref: '@supabase/supabase-js.index.SupabaseClient.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.
+ gt():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.gt'
examples:
- - name: Remove all channels
+ - name: With `select()`
isSpotlight: true
js: |
```js
- supabase.removeAllChannels()
+ const { data, error } = await supabase
+ .from('cities')
+ .select('name, country_id')
+ .gt('country_id', 250)
```
-
- getChannels():
- title: 'getChannels()'
- $ref: '@supabase/supabase-js.index.SupabaseClient.getChannels'
- examples:
- - name: Get all channels
- isSpotlight: true
+ - name: With `update()`
js: |
```js
- const channels = supabase.getChannels()
+ const { data, error } = await supabase
+ .from('cities')
+ .update({ name: 'Mordor' })
+ .gt('country_id', 250)
```
-
- storage.listBuckets():
- title: 'listBuckets()'
- $ref: '@supabase/storage-js.packages/StorageBucketApi.default.listBuckets'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: `select`
- - `objects` table permissions: none
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
- examples:
- - name: List buckets
- isSpotlight: true
+ - name: With `delete()`
js: |
```js
const { data, error } = await supabase
- .storage
- .listBuckets()
+ .from('cities')
+ .delete()
+ .gt('country_id', 250)
```
-
- storage.getBucket():
- title: 'getBucket()'
- $ref: '@supabase/storage-js.packages/StorageBucketApi.default.getBucket'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: `select`
- - `objects` table permissions: none
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
- examples:
- - name: Get bucket
- isSpotlight: true
+ - name: With `rpc()`
js: |
```js
+ // Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .storage
- .getBucket('avatars')
+ .rpc('echo_all_cities')
+ .gt('country_id', 250)
```
- storage.createBucket():
- title: 'createBucket()'
- $ref: '@supabase/storage-js.packages/StorageBucketApi.default.createBucket'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: `insert`
- - `objects` table permissions: none
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ gte():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.gte'
examples:
- - name: Create bucket
+ - name: With `select()`
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .storage
- .createBucket('avatars', { public: false })
+ .from('cities')
+ .select('name, country_id')
+ .gte('country_id', 250)
```
-
- storage.emptyBucket():
- title: 'emptyBucket()'
- $ref: '@supabase/storage-js.packages/StorageBucketApi.default.emptyBucket'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: `select`
- - `objects` table permissions: `select` and `delete`
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
- examples:
- - name: Empty bucket
- isSpotlight: true
+ - name: With `update()`
js: |
```js
const { data, error } = await supabase
- .storage
- .emptyBucket('avatars')
+ .from('cities')
+ .update({ name: 'Mordor' })
+ .gte('country_id', 250)
```
- storage.updateBucket():
- title: 'updateBucket()'
- $ref: '@supabase/storage-js.packages/StorageBucketApi.default.updateBucket'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: `update`
- - `objects` table permissions: none
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
- examples:
- - name: Update bucket
- isSpotlight: true
+ - name: With `delete()`
js: |
```js
const { data, error } = await supabase
- .storage
- .updateBucket('avatars', { public: false })
+ .from('cities')
+ .delete()
+ .gte('country_id', 250)
```
-
- storage.deleteBucket():
- title: 'deleteBucket()'
- $ref: '@supabase/storage-js.packages/StorageBucketApi.default.deleteBucket'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: `select` and `delete`
- - `objects` table permissions: none
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
- examples:
- - name: Delete bucket
- isSpotlight: true
+ - name: With `rpc()`
js: |
```js
+ // Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .storage
- .deleteBucket('avatars')
+ .rpc('echo_all_cities')
+ .gte('country_id', 250)
```
- storage.from.upload():
- title: 'from.upload()'
- $ref: '@supabase/storage-js.packages/StorageFileApi.default.upload'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: none
- - `objects` table permissions: `insert`
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
- - For React Native, using either `Blob`, `File` or `FormData` does not work as intended. Upload file using `ArrayBuffer` from base64 file data instead, see example below.
+ lt():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.lt'
examples:
- - name: Upload file
+ - name: With `select()`
isSpotlight: true
js: |
```js
- const avatarFile = event.target.files[0]
const { data, error } = await supabase
- .storage
- .from('avatars')
- .upload('public/avatar1.png', avatarFile, {
- cacheControl: '3600',
- upsert: false
- })
+ .from('cities')
+ .select('name, country_id')
+ .lt('country_id', 250)
```
- - name: Upload file using `ArrayBuffer` from base64 file data
+ - name: With `update()`
js: |
```js
- import { decode } from 'base64-arraybuffer'
-
const { data, error } = await supabase
- .storage
- .from('avatars')
- .upload('public/avatar1.png', decode('base64FileData'), {
- contentType: 'image/png'
- })
+ .from('cities')
+ .update({ name: 'Mordor' })
+ .lt('country_id', 250)
```
-
- storage.from.update():
- title: 'from.update()'
- $ref: '@supabase/storage-js.packages/StorageFileApi.default.update'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: none
- - `objects` table permissions: `update` and `select`
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
- - For React Native, using either `Blob`, `File` or `FormData` does not work as intended. Update file using `ArrayBuffer` from base64 file data instead, see example below.
- examples:
- - name: Update file
- isSpotlight: true
+ - name: With `delete()`
js: |
```js
- const avatarFile = event.target.files[0]
const { data, error } = await supabase
- .storage
- .from('avatars')
- .update('public/avatar1.png', avatarFile, {
- cacheControl: '3600',
- upsert: false
- })
+ .from('cities')
+ .delete()
+ .lt('country_id', 250)
```
- - name: Update file using `ArrayBuffer` from base64 file data
+ - name: With `rpc()`
js: |
```js
- import {decode} from 'base64-arraybuffer'
-
+ // Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .storage
- .from('avatars')
- .update('public/avatar1.png', decode('base64FileData'), {
- contentType: 'image/png'
- })
+ .rpc('echo_all_cities')
+ .lt('country_id', 250)
```
- storage.from.move():
- title: 'from.move()'
- $ref: '@supabase/storage-js.packages/StorageFileApi.default.move'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: none
- - `objects` table permissions: `update` and `select`
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ lte():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.lte'
examples:
- - name: Move file
+ - name: With `select()`
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .storage
- .from('avatars')
- .move('public/avatar1.png', 'private/avatar2.png')
+ .from('cities')
+ .select('name, country_id')
+ .lte('country_id', 250)
```
-
- storage.from.copy():
- title: 'from.copy()'
- $ref: '@supabase/storage-js.packages/StorageFileApi.default.copy'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: none
- - `objects` table permissions: `insert` and `select`
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
- examples:
- - name: Copy file
- isSpotlight: true
+ - name: With `update()`
js: |
```js
const { data, error } = await supabase
- .storage
- .from('avatars')
- .copy('public/avatar1.png', 'private/avatar2.png')
+ .from('cities')
+ .update({ name: 'Mordor' })
+ .lte('country_id', 250)
```
-
- storage.from.createSignedUrl():
- title: 'from.createSignedUrl()'
- $ref: '@supabase/storage-js.packages/StorageFileApi.default.createSignedUrl'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: none
- - `objects` table permissions: `select`
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
- examples:
- - name: Create Signed URL
- isSpotlight: true
+ - name: With `delete()`
js: |
```js
const { data, error } = await supabase
- .storage
- .from('avatars')
- .createSignedUrl('folder/avatar1.png', 60)
+ .from('cities')
+ .delete()
+ .lte('country_id', 250)
+ ```
+ - name: With `rpc()`
+ js: |
+ ```js
+ // Only valid if the Postgres function returns a table type.
+ const { data, error } = await supabase
+ .rpc('echo_all_cities')
+ .lte('country_id', 250)
```
- storage.from.createSignedUrls():
- title: 'from.createSignedUrls()'
- $ref: '@supabase/storage-js.packages/StorageFileApi.default.createSignedUrls'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: none
- - `objects` table permissions: `select`
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ like():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.like'
examples:
- - name: Create Signed URLs
+ - name: With `select()`
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .storage
- .from('avatars')
- .createSignedUrls(['folder/avatar1.png', 'folder/avatar2.png'], 60)
+ .from('cities')
+ .select('name, country_id')
+ .like('name', '%la%')
```
-
- storage.from.getPublicUrl():
- title: 'from.getPublicUrl()'
- $ref: '@supabase/storage-js.packages/StorageFileApi.default.getPublicUrl'
- notes: |
- - The bucket needs to be set to public, either via [updateBucket()](/docs/reference/javascript/storage-updatebucket) or by going to Storage on [app.supabase.com](https://app.supabase.com), clicking the overflow menu on a bucket and choosing "Make public"
- - RLS policy permissions required:
- - `buckets` table permissions: none
- - `objects` table permissions: none
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
- examples:
- - name: Returns the URL for an asset in a public bucket
- isSpotlight: true
+ - name: With `update()`
js: |
```js
- const { data } = supabase
- .storage
- .from('public-bucket')
- .getPublicUrl('folder/avatar1.png')
+ const { data, error } = await supabase
+ .from('cities')
+ .update({ name: 'Mordor' })
+ .like('name', '%la%')
```
-
- storage.from.download():
- title: 'from.download()'
- $ref: '@supabase/storage-js.packages/StorageFileApi.default.download'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: none
- - `objects` table permissions: `select`
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
- examples:
- - name: Download file
- isSpotlight: true
+ - name: With `delete()`
js: |
```js
const { data, error } = await supabase
- .storage
- .from('avatars')
- .download('folder/avatar1.png')
+ .from('cities')
+ .delete()
+ .like('name', '%la%')
```
-
- storage.from.remove():
- title: 'from.remove()'
- $ref: '@supabase/storage-js.packages/StorageFileApi.default.remove'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: none
- - `objects` table permissions: `delete` and `select`
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
- examples:
- - name: Delete file
- isSpotlight: true
+ - name: With `rpc()`
js: |
```js
+ // Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .storage
- .from('avatars')
- .remove(['folder/avatar1.png'])
+ .rpc('echo_all_cities')
+ .like('name', '%la%')
```
- storage.from.list():
- title: 'from.list()'
- $ref: '@supabase/storage-js.packages/StorageFileApi.default.list'
- notes: |
- - RLS policy permissions required:
- - `buckets` table permissions: none
- - `objects` table permissions: `select`
- - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ ilike():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.ilike'
examples:
- - name: List files in a bucket
+ - name: With `select()`
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .storage
- .from('avatars')
- .list('folder', {
- limit: 100,
- offset: 0,
- sortBy: { column: 'name', order: 'asc' },
- })
+ .from('cities')
+ .select('name, country_id')
+ .ilike('name', '%la%')
```
- - name: Search files in a bucket
+ - name: With `update()`
js: |
```js
const { data, error } = await supabase
- .storage
- .from('avatars')
- .list('folder', {
- limit: 100,
- offset: 0,
- sortBy: { column: 'name', order: 'asc' },
- search: 'jon'
- })
+ .from('cities')
+ .update({ name: 'Mordor' })
+ .ilike('name', '%la%')
```
-
- Using Modifiers:
- description: |
- Modifiers can be used on `select()` queries.
-
- If a Postgres function returns a table response, you can also apply modifiers to the `rpc()` function.
-
- limit():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.limit'
- examples:
- - name: With `select()`
- isSpotlight: true
+ - name: With `delete()`
js: |
```js
const { data, error } = await supabase
.from('cities')
- .select('name, country_id')
- .limit(1)
+ .delete()
+ .ilike('name', '%la%')
```
- - name: With embedded resources
+ - name: With `rpc()`
js: |
```js
+ // Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .from('countries')
- .select('name, cities(name)')
- .eq('name', 'United States')
- .limit(1, { foreignTable: 'cities' })
+ .rpc('echo_all_cities')
+ .ilike('name', '%la%')
```
- order():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.order'
+ is():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.is'
examples:
- name: With `select()`
isSpotlight: true
@@ -1551,48 +1334,36 @@ pages:
```js
const { data, error } = await supabase
.from('cities')
- .select('name', 'country_id')
- .order('id', { ascending: false })
+ .select('name, country_id')
+ .is('name', null)
```
- - name: With embedded resources
+ - name: With `update()`
js: |
```js
const { data, error } = await supabase
- .from('countries')
- .select('name, cities(name)')
- .eq('name', 'United States')
- .order('name', {foreignTable: 'cities'})
+ .from('cities')
+ .update({ name: 'Mordor' })
+ .is('name', null)
```
-
- range():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.range'
- examples:
- - name: With `select()`
- isSpotlight: true
+ - name: With `delete()`
js: |
```js
const { data, error } = await supabase
.from('cities')
- .select('name, country_id')
- .range(0,3)
+ .delete()
+ .is('name', null)
```
-
- single():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.single'
- examples:
- - name: With `select()`
- isSpotlight: true
+ - name: With `rpc()`
js: |
```js
+ // Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .from('cities')
- .select('name, country_id')
- .limit(1)
- .single()
+ .rpc('echo_all_cities')
+ .is('name', null)
```
- maybeSingle():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.maybeSingle'
+ in():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.in'
examples:
- name: With `select()`
isSpotlight: true
@@ -1601,114 +1372,44 @@ pages:
const { data, error } = await supabase
.from('cities')
.select('name, country_id')
- .eq('name', 'Singapore')
- .maybeSingle()
+ .in('name', ['Rio de Janeiro', 'San Francisco'])
```
-
- Using Filters:
- description: |
- Filters can be used on `select()`, `update()`, and `delete()` queries.
-
- If a Postgres function returns a table response, you can also apply filters.
-
- ### Applying Filters
-
- You must apply your filters to the end of your query. For example:
-
- ```js
- const { data, error } = await supabase
- .from('cities')
- .select('name, country_id')
- .eq('name', 'The Shire') // Correct
-
- const { data, error } = await supabase
- .from('cities')
- .eq('name', 'The Shire') // Incorrect
- .select('name, country_id')
- ```
-
- ### Chaining
-
- Filters can be chained together to produce advanced queries. For example:
-
- ```js
- const { data, error } = await supabase
- .from('cities')
- .select('name, country_id')
- .gte('population', 1000)
- .lt('population', 10000)
- ```
-
- ### Conditional Chaining
-
- Filters can be built up one step at a time and then executed. For example:
-
- ```js
- const filterByName = null
- const filterPopLow = 1000
- const filterPopHigh = 10000
-
- let query = supabase
- .from('cities')
- .select('name, country_id')
-
- if (filterByName) { query = query.eq('name', filterByName) }
- if (filterPopLow) { query = query.gte('population', filterPopLow) }
- if (filterPopHigh) { query = query.lt('population', filterPopHigh) }
-
- const { data, error } = await query
- ```
-
- .or():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.or'
- notes: |
- - `.or()` expects you to use the raw [PostgREST syntax](https://postgrest.org/en/stable/api.html#horizontal-filtering-rows) for the filter names and values.
-
- ```js
- .or('id.in.(6,7), arraycol.cs.{"a","b"}') // Use Postgres list () for in filter. Array {} for array column and 'cs' for contains.
- .or(`id.in.(${arrList}),arraycol.cs.{${arr}}`) // You can insert a javascipt array for list or array on array column.
- .or(`id.in.(${arrList}),rangecol.cs.[${arrRange})`) // You can insert a javascipt array for list or range on a range column.
- ```
- examples:
- - name: With `select()`
- isSpotlight: true
+ - name: With `update()`
js: |
```js
const { data, error } = await supabase
.from('cities')
- .select('name, country_id')
- .or('id.eq.20,id.eq.30')
+ .update({ name: 'Mordor' })
+ .in('name', ['Rio de Janeiro', 'San Francisco'])
```
- - name: Use `or` with `and`
- isSpotlight: true
+ - name: With `delete()`
js: |
```js
const { data, error } = await supabase
.from('cities')
- .select('name, country_id')
- .or('id.gt.20,and(name.eq.New Zealand,name.eq.France)')
+ .delete()
+ .in('name', ['Rio de Janeiro', 'San Francisco'])
```
- - name: Use `or` on foreign tables
- isSpotlight: true
+ - name: With `rpc()`
js: |
```js
+ // Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .from('countries')
- .select('id, cities(*)')
- .or('name.eq.Wellington,name.eq.Paris', { foreignTable: "cities" })
+ .rpc('echo_all_cities')
+ .in('name', ['Rio de Janeiro', 'San Francisco'])
```
- .not():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.not'
+ contains():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.contains'
notes: |
- - `.not()` expects you to use the raw [PostgREST syntax](https://postgrest.org/en/stable/api.html#horizontal-filtering-rows) for the filter names and values.
+ - `.contains()` can work on array columns or range columns.
+ It is very useful for finding rows where a tag array contains all the values in the filter array.
```js
- .not('name','eq','Paris')
- .not('arraycol','cs','{"a","b"}') // Use Postgres array {} for array column and 'cs' for contains.
- .not('rangecol','cs','(1,2]') // Use Postgres range syntax for range column.
- .not('id','in','(6,7)') // Use Postgres list () for in filter.
- .not('id','in',`(${arr})`) // You can insert a javascript array.
+ .contains('arraycol',["a","b"]) // You can use a javascript array for an array column
+ .contains('arraycol','{"a","b"}') // You can use a string with Postgres array {} for array column.
+ .contains('rangecol','(1,2]') // Use Postgres range syntax for range column.
+ .contains('rangecol',`(${arr}]`) // You can insert an array into a string.
```
examples:
- name: With `select()`
@@ -1716,333 +1417,373 @@ pages:
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .select('name, country_id')
- .not('name', 'eq', 'Paris')
+ .from('countries')
+ .select('name, id, main_exports')
+ .contains('main_exports', ['oil'])
```
- name: With `update()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.update({ name: 'Mordor' })
- .not('name', 'eq', 'Paris')
+ .contains('main_exports', ['oil'])
```
- name: With `delete()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.delete()
- .not('name', 'eq', 'Paris')
+ .contains('main_exports', ['oil'])
```
- name: With `rpc()`
js: |
```js
// Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_cities')
- .not('name', 'eq', 'Paris')
+ .rpc('echo_all_countries')
+ .contains('main_exports', ['oil'])
```
- .match():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.match'
+ containedBy():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.containedBy'
+ notes: |
+ - `.containedBy()` can work on array columns or range columns.
+
+ ```js
+ .containedBy('arraycol',["a","b"]) // You can use a javascript array for an array column
+ .containedBy('arraycol','{"a","b"}') // You can use a string with Postgres array {} for array column.
+ .containedBy('rangecol','(1,2]') // Use Postgres range syntax for range column.
+ .containedBy('rangecol',`(${arr}]`) // You can insert an array into a string.
+ ```
examples:
- name: With `select()`
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .select('name, country_id')
- .match({name: 'Beijing', country_id: 156})
+ .from('countries')
+ .select('name, id, main_exports')
+ .containedBy('main_exports', ['cars', 'food', 'machine'])
```
- name: With `update()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.update({ name: 'Mordor' })
- .match({name: 'Beijing', country_id: 156})
+ .containedBy('main_exports', ['orks', 'surveillance', 'evil'])
```
- name: With `delete()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.delete()
- .match({name: 'Beijing', country_id: 156})
+ .containedBy('main_exports', ['cars', 'food', 'machine'])
```
- name: With `rpc()`
js: |
```js
// Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_cities')
- .match({name: 'Beijing', country_id: 156})
+ .rpc('echo_all_countries')
+ .containedBy('main_exports', ['cars', 'food', 'machine'])
```
- .eq():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.eq'
+ rangeGt():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.rangeGt'
examples:
- name: With `select()`
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .select('name, country_id')
- .eq('name', 'The shire')
+ .from('countries')
+ .select('name, id, population_range_millions')
+ .rangeGt('population_range_millions', '[150, 250]')
```
- name: With `update()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.update({ name: 'Mordor' })
- .eq('name', 'San Francisco')
+ .rangeGt('population_range_millions', '[150, 250]')
```
- name: With `delete()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.delete()
- .eq('name', 'Mordor')
+ .rangeGt('population_range_millions', '[150, 250]')
```
- name: With `rpc()`
js: |
```js
// Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_cities')
- .eq('name', 'San Francisco')
+ .rpc('echo_all_countries')
+ .rangeGt('population_range_millions', '[150, 250]')
```
- .neq():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.neq'
+ rangeGte():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.rangeGte'
examples:
- name: With `select()`
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .select('name, country_id')
- .neq('name', 'The shire')
+ .from('countries')
+ .select('name, id, population_range_millions')
+ .rangeGte('population_range_millions', '[150, 250]')
```
- name: With `update()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.update({ name: 'Mordor' })
- .neq('name', 'San Francisco')
+ .rangeGte('population_range_millions', '[150, 250]')
```
- name: With `delete()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.delete()
- .neq('name', 'Mordor')
+ .rangeGte('population_range_millions', '[150, 250]')
```
- name: With `rpc()`
js: |
```js
// Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_cities')
- .neq('name', 'Lagos')
+ .rpc('echo_all_countries')
+ .rangeGte('population_range_millions', '[150, 250]')
```
- .gt():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.gt'
+ rangeLt():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.rangeLt'
examples:
- name: With `select()`
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .select('name, country_id')
- .gt('country_id', 250)
+ .from('countries')
+ .select('name, id, population_range_millions')
+ .rangeLt('population_range_millions', '[150, 250]')
```
- name: With `update()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.update({ name: 'Mordor' })
- .gt('country_id', 250)
+ .rangeLt('population_range_millions', '[150, 250]')
```
- name: With `delete()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.delete()
- .gt('country_id', 250)
+ .rangeLt('population_range_millions', '[150, 250]')
```
- name: With `rpc()`
js: |
```js
// Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_cities')
- .gt('country_id', 250)
+ .rpc('echo_all_countries')
+ .rangeLt('population_range_millions', '[150, 250]')
```
- .gte():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.gte'
+ rangeLte():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.rangeLte'
examples:
- name: With `select()`
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .select('name, country_id')
- .gte('country_id', 250)
+ .from('countries')
+ .select('name, id, population_range_millions')
+ .rangeLte('population_range_millions', '[150, 250]')
```
- name: With `update()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.update({ name: 'Mordor' })
- .gte('country_id', 250)
+ .rangeLte('population_range_millions', '[150, 250]')
```
- name: With `delete()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.delete()
- .gte('country_id', 250)
+ .rangeLte('population_range_millions', '[150, 250]')
```
- name: With `rpc()`
js: |
```js
// Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_cities')
- .gte('country_id', 250)
+ .rpc('echo_all_countries')
+ .rangeLte('population_range_millions', '[150, 250]')
```
- .lt():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.lt'
+ rangeAdjacent():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.rangeAdjacent'
examples:
- name: With `select()`
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .select('name, country_id')
- .lt('country_id', 250)
+ .from('countries')
+ .select('name, id, population_range_millions')
+ .rangeAdjacent('population_range_millions', '[70, 185]')
```
- name: With `update()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.update({ name: 'Mordor' })
- .lt('country_id', 250)
+ .rangeAdjacent('population_range_millions', '[70, 185]')
```
- name: With `delete()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.delete()
- .lt('country_id', 250)
+ .rangeAdjacent('population_range_millions', '[70, 185]')
```
- name: With `rpc()`
js: |
```js
// Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_cities')
- .lt('country_id', 250)
+ .rpc('echo_all_countries')
+ .rangeAdjacent('population_range_millions', '[70, 185]')
```
- .lte():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.lte'
+ overlaps():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.overlaps'
+ notes: |
+ - `.overlaps()` can work on array columns or range columns.
+
+ ```js
+ .overlaps('arraycol',["a","b"]) // You can use a javascript array for an array column
+ .overlaps('arraycol','{"a","b"}') // You can use a string with Postgres array {} for array column.
+ .overlaps('rangecol','(1,2]') // Use Postgres range syntax for range column.
+ .overlaps('rangecol',`(${arr}]`) // You can insert an array into a string.
+ ```
examples:
- name: With `select()`
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .select('name, country_id')
- .lte('country_id', 250)
+ .from('countries')
+ .select('name, id, main_exports')
+ .overlaps('main_exports', ['computers', 'minerals'])
```
- name: With `update()`
js: |
```js
- const { data, error } = await supabase
- .from('cities')
+ let countries = await supabase
+ .from('countries')
.update({ name: 'Mordor' })
- .lte('country_id', 250)
+ .overlaps('main_exports', ['computers', 'minerals'])
```
- name: With `delete()`
js: |
```js
const { data, error } = await supabase
- .from('cities')
+ .from('countries')
.delete()
- .lte('country_id', 250)
+ .overlaps('main_exports', ['computers', 'minerals'])
```
- name: With `rpc()`
js: |
```js
// Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_cities')
- .lte('country_id', 250)
+ .rpc('echo_all_countries')
+ .overlaps('main_exports', ['computers', 'minerals'])
```
- .like():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.like'
+ textSearch():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.textSearch'
examples:
- - name: With `select()`
- isSpotlight: true
+ - name: Text search
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .select('name, country_id')
- .like('name', '%la%')
+ .from('quotes')
+ .select('catchphrase')
+ .textSearch('catchphrase', `'fat' & 'cat'`, {
+ config: 'english'
+ })
```
- - name: With `update()`
+ - name: Basic normalization
+ description: Uses PostgreSQL's `plainto_tsquery` function.
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .update({ name: 'Mordor' })
- .like('name', '%la%')
+ .from('quotes')
+ .select('catchphrase')
+ .textSearch('catchphrase', `'fat' & 'cat'`, {
+ type: 'plain',
+ config: 'english'
+ })
```
- - name: With `delete()`
+ - name: Full normalization
+ description: Uses PostgreSQL's `phraseto_tsquery` function.
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .delete()
- .like('name', '%la%')
+ .from('quotes')
+ .select('catchphrase')
+ .textSearch('catchphrase', `'fat' & 'cat'`, {
+ type: 'phrase',
+ config: 'english'
+ })
```
- - name: With `rpc()`
+ - name: Websearch
+ description: |
+ Uses PostgreSQL's `websearch_to_tsquery` function.
+ This function will never raise syntax errors, which makes it possible to use raw user-supplied input for search, and can be used
+ with advanced operators.
+
+ - `unquoted text`: text not inside quote marks will be converted to terms separated by & operators, as if processed by plainto_tsquery.
+ - `"quoted text"`: text inside quote marks will be converted to terms separated by <-> operators, as if processed by phraseto_tsquery.
+ - `OR`: the word “or” will be converted to the | operator.
+ - `-`: a dash will be converted to the ! operator.
+
js: |
```js
- // Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_cities')
- .like('name', '%la%')
+ .from('quotes')
+ .select('catchphrase')
+ .textSearch('catchphrase', `'fat or cat'`, {
+ type: 'websearch',
+ config: 'english'
+ })
```
- .ilike():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.ilike'
+ match():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.match'
examples:
- name: With `select()`
isSpotlight: true
@@ -2051,7 +1792,7 @@ pages:
const { data, error } = await supabase
.from('cities')
.select('name, country_id')
- .ilike('name', '%la%')
+ .match({name: 'Beijing', country_id: 156})
```
- name: With `update()`
js: |
@@ -2059,7 +1800,7 @@ pages:
const { data, error } = await supabase
.from('cities')
.update({ name: 'Mordor' })
- .ilike('name', '%la%')
+ .match({name: 'Beijing', country_id: 156})
```
- name: With `delete()`
js: |
@@ -2067,7 +1808,7 @@ pages:
const { data, error } = await supabase
.from('cities')
.delete()
- .ilike('name', '%la%')
+ .match({name: 'Beijing', country_id: 156})
```
- name: With `rpc()`
js: |
@@ -2075,11 +1816,21 @@ pages:
// Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
.rpc('echo_all_cities')
- .ilike('name', '%la%')
+ .match({name: 'Beijing', country_id: 156})
```
- .is():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.is'
+ not():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.not'
+ notes: |
+ - `.not()` expects you to use the raw [PostgREST syntax](https://postgrest.org/en/stable/api.html#horizontal-filtering-rows) for the filter names and values.
+
+ ```js
+ .not('name','eq','Paris')
+ .not('arraycol','cs','{"a","b"}') // Use Postgres array {} for array column and 'cs' for contains.
+ .not('rangecol','cs','(1,2]') // Use Postgres range syntax for range column.
+ .not('id','in','(6,7)') // Use Postgres list () for in filter.
+ .not('id','in',`(${arr})`) // You can insert a javascript array.
+ ```
examples:
- name: With `select()`
isSpotlight: true
@@ -2088,7 +1839,7 @@ pages:
const { data, error } = await supabase
.from('cities')
.select('name, country_id')
- .is('name', null)
+ .not('name', 'eq', 'Paris')
```
- name: With `update()`
js: |
@@ -2096,7 +1847,7 @@ pages:
const { data, error } = await supabase
.from('cities')
.update({ name: 'Mordor' })
- .is('name', null)
+ .not('name', 'eq', 'Paris')
```
- name: With `delete()`
js: |
@@ -2104,7 +1855,7 @@ pages:
const { data, error } = await supabase
.from('cities')
.delete()
- .is('name', null)
+ .not('name', 'eq', 'Paris')
```
- name: With `rpc()`
js: |
@@ -2112,11 +1863,19 @@ pages:
// Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
.rpc('echo_all_cities')
- .is('name', null)
+ .not('name', 'eq', 'Paris')
```
- .in():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.in'
+ or():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.or'
+ notes: |
+ - `.or()` expects you to use the raw [PostgREST syntax](https://postgrest.org/en/stable/api.html#horizontal-filtering-rows) for the filter names and values.
+
+ ```js
+ .or('id.in.(6,7), arraycol.cs.{"a","b"}') // Use Postgres list () for in filter. Array {} for array column and 'cs' for contains.
+ .or(`id.in.(${arrList}),arraycol.cs.{${arr}}`) // You can insert a javascipt array for list or array on array column.
+ .or(`id.in.(${arrList}),rangecol.cs.[${arrRange})`) // You can insert a javascipt array for list or range on a range column.
+ ```
examples:
- name: With `select()`
isSpotlight: true
@@ -2125,44 +1884,36 @@ pages:
const { data, error } = await supabase
.from('cities')
.select('name, country_id')
- .in('name', ['Rio de Janeiro', 'San Francisco'])
- ```
- - name: With `update()`
- js: |
- ```js
- const { data, error } = await supabase
- .from('cities')
- .update({ name: 'Mordor' })
- .in('name', ['Rio de Janeiro', 'San Francisco'])
+ .or('id.eq.20,id.eq.30')
```
- - name: With `delete()`
+ - name: Use `or` with `and`
+ isSpotlight: true
js: |
```js
const { data, error } = await supabase
.from('cities')
- .delete()
- .in('name', ['Rio de Janeiro', 'San Francisco'])
+ .select('name, country_id')
+ .or('id.gt.20,and(name.eq.New Zealand,name.eq.France)')
```
- - name: With `rpc()`
+ - name: Use `or` on foreign tables
+ isSpotlight: true
js: |
```js
- // Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_cities')
- .in('name', ['Rio de Janeiro', 'San Francisco'])
+ .from('countries')
+ .select('id, cities(*)')
+ .or('name.eq.Wellington,name.eq.Paris', { foreignTable: "cities" })
```
- .contains():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.contains'
+ filter():
+ $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.filter'
notes: |
- - `.contains()` can work on array columns or range columns.
- It is very useful for finding rows where a tag array contains all the values in the filter array.
-
+ - `.filter()` expects you to use the raw [PostgREST syntax](https://postgrest.org/en/stable/api.html#horizontal-filtering-rows) for the filter names and values, so it should only be used as an escape hatch in case other filters don't work.
```js
- .contains('arraycol',["a","b"]) // You can use a javascript array for an array column
- .contains('arraycol','{"a","b"}') // You can use a string with Postgres array {} for array column.
- .contains('rangecol','(1,2]') // Use Postgres range syntax for range column.
- .contains('rangecol',`(${arr}]`) // You can insert an array into a string.
+ .filter('arraycol','cs','{"a","b"}') // Use Postgres array {} for array column and 'cs' for contains.
+ .filter('rangecol','cs','(1,2]') // Use Postgres range syntax for range column.
+ .filter('id','in','(6,7)') // Use Postgres list () for in filter.
+ .filter('id','in',`(${arr})`) // You can insert a javascript array.
```
examples:
- name: With `select()`
@@ -2170,420 +1921,670 @@ pages:
js: |
```js
const { data, error } = await supabase
- .from('countries')
- .select('name, id, main_exports')
- .contains('main_exports', ['oil'])
+ .from('cities')
+ .select('name, country_id')
+ .filter('name', 'in', '("Paris","Tokyo")')
```
- name: With `update()`
js: |
```js
const { data, error } = await supabase
- .from('countries')
+ .from('cities')
.update({ name: 'Mordor' })
- .contains('main_exports', ['oil'])
+ .filter('name', 'in', '("Paris","Tokyo")')
```
- name: With `delete()`
js: |
```js
const { data, error } = await supabase
- .from('countries')
+ .from('cities')
.delete()
- .contains('main_exports', ['oil'])
+ .filter('name', 'in', '("Paris","Tokyo")')
```
- name: With `rpc()`
js: |
```js
// Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_countries')
- .contains('main_exports', ['oil'])
+ .rpc('echo_all_cities')
+ .filter('name', 'in', '("Paris","Tokyo")')
+ ```
+ - name: Filter embedded resources
+ js: |
+ ```js
+ const { data, error } = await supabase
+ .from('cities')
+ .select('name, countries ( name )')
+ .filter('countries.name', 'in', '("France","Japan")')
```
- .containedBy():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.containedBy'
- notes: |
- - `.containedBy()` can work on array columns or range columns.
+ Using Modifiers:
+ description: |
+ Modifiers can be used on `select()` queries.
- ```js
- .containedBy('arraycol',["a","b"]) // You can use a javascript array for an array column
- .containedBy('arraycol','{"a","b"}') // You can use a string with Postgres array {} for array column.
- .containedBy('rangecol','(1,2]') // Use Postgres range syntax for range column.
- .containedBy('rangecol',`(${arr}]`) // You can insert an array into a string.
- ```
+ If a Postgres function returns a table response, you can also apply modifiers to the `rpc()` function.
+
+ order():
+ $ref: '@supabase/postgrest-js.PostgrestTransformBuilder.order'
examples:
- name: With `select()`
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('countries')
- .select('name, id, main_exports')
- .containedBy('main_exports', ['cars', 'food', 'machine'])
- ```
- - name: With `update()`
- js: |
- ```js
- const { data, error } = await supabase
- .from('countries')
- .update({ name: 'Mordor' })
- .containedBy('main_exports', ['orks', 'surveillance', 'evil'])
+ .from('cities')
+ .select('name', 'country_id')
+ .order('id', { ascending: false })
```
- - name: With `delete()`
+ - name: With embedded resources
js: |
```js
const { data, error } = await supabase
.from('countries')
- .delete()
- .containedBy('main_exports', ['cars', 'food', 'machine'])
- ```
- - name: With `rpc()`
- js: |
- ```js
- // Only valid if the Postgres function returns a table type.
- const { data, error } = await supabase
- .rpc('echo_all_countries')
- .containedBy('main_exports', ['cars', 'food', 'machine'])
+ .select('name, cities(name)')
+ .eq('name', 'United States')
+ .order('name', {foreignTable: 'cities'})
```
- .rangeLt():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.rangeLt'
+ limit():
+ $ref: '@supabase/postgrest-js.PostgrestTransformBuilder.limit'
examples:
- name: With `select()`
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('countries')
- .select('name, id, population_range_millions')
- .rangeLt('population_range_millions', '[150, 250]')
+ .from('cities')
+ .select('name, country_id')
+ .limit(1)
```
- - name: With `update()`
+ - name: With embedded resources
js: |
```js
const { data, error } = await supabase
.from('countries')
- .update({ name: 'Mordor' })
- .rangeLt('population_range_millions', '[150, 250]')
+ .select('name, cities(name)')
+ .eq('name', 'United States')
+ .limit(1, { foreignTable: 'cities' })
```
- - name: With `delete()`
+
+ range():
+ $ref: '@supabase/postgrest-js.PostgrestTransformBuilder.range'
+ examples:
+ - name: With `select()`
+ isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('countries')
- .delete()
- .rangeLt('population_range_millions', '[150, 250]')
+ .from('cities')
+ .select('name, country_id')
+ .range(0,3)
```
- - name: With `rpc()`
+
+ single():
+ $ref: '@supabase/postgrest-js.PostgrestTransformBuilder.single'
+ examples:
+ - name: With `select()`
+ isSpotlight: true
js: |
```js
- // Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_countries')
- .rangeLt('population_range_millions', '[150, 250]')
+ .from('cities')
+ .select('name, country_id')
+ .limit(1)
+ .single()
```
- .rangeGt():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.rangeGt'
+ maybeSingle():
+ $ref: '@supabase/postgrest-js.PostgrestTransformBuilder.maybeSingle'
examples:
- name: With `select()`
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('countries')
- .select('name, id, population_range_millions')
- .rangeGt('population_range_millions', '[150, 250]')
+ .from('cities')
+ .select('name, country_id')
+ .eq('name', 'Singapore')
+ .maybeSingle()
```
- - name: With `update()`
+
+ invoke():
+ title: 'invoke()'
+ description: |
+ Invoke a Supabase Function.
+ $ref: '@supabase/functions-js.index.FunctionsClient.invoke'
+ notes: |
+ - Requires an Authorization header.
+ - Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec.
+ - When you pass in a body to your function, we automatically attach the Content-Type header for `Blob`, `ArrayBuffer`, `File`, `FormData` and `String`. If it doesn't match any of these types we assume the payload is `json`, serialise it and attach the `Content-Type` header as `application/json`. You can override this behaviour by passing in a `Content-Type` header of your own.
+ - Responses are automatically parsed as `json`, `blob` and `form-data` depending on the `Content-Type` header sent by your function. Responses are parsed as `text` by default.
+ examples:
+ - name: Basic invocation.
+ description:
+ isSpotlight: true
js: |
```js
- const { data, error } = await supabase
- .from('countries')
- .update({ name: 'Mordor' })
- .rangeGt('population_range_millions', '[150, 250]')
+ const { data: user, error } = await supabase.functions.invoke('hello', {
+ body: { foo: 'bar' }
+ })
```
- - name: With `delete()`
+ - name: Error handling.
+ description: |
+ A `FunctionsHttpError` error is returned if your function throws an error, `FunctionsRelayError` if the Supabase Relay has an error processing your function and `FunctionsFetchError` if there is a network error in calling your function.
+ isSpotlight: true
js: |
```js
- const { data, error } = await supabase
- .from('countries')
- .delete()
- .rangeGt('population_range_millions', '[150, 250]')
+ import { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError } from "@supabase/supabase-js";
+
+ const { data: user, error } = await supabase.functions.invoke('hello', {
+ headers: {
+ "my-custom-header": 'my-custom-header-value'
+ },
+ body: { foo: 'bar' }
+ })
+
+ if (error instanceof FunctionsHttpError) {
+ console.log('Function returned an error', error.message)
+ } else if (error instanceof FunctionsRelayError) {
+ console.log('Relay error:', error.message)
+ } else if (error instanceof FunctionsFetchError) {
+ console.log('Fetch error:', error.message)
+ }
```
- - name: With `rpc()`
+ - name: Passing custom headers.
+ description: |
+ You can pass custom headers to your function. Note: supabase-js automatically passes the `Authorization` header with the signed in user's JWT.
+ isSpotlight: true
js: |
```js
- // Only valid if the Postgres function returns a table type.
- const { data, error } = await supabase
- .rpc('echo_all_countries')
- .rangeGt('population_range_millions', '[150, 250]')
+ const { data: user, error } = await supabase.functions.invoke('hello', {
+ headers: {
+ "my-custom-header": 'my-custom-header-value'
+ },
+ body: { foo: 'bar' }
+ })
```
- .rangeGte():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.rangeGte'
- examples:
- - name: With `select()`
+ subscribe():
+ title: 'on().subscribe()'
+ $ref: '@supabase/realtime-js.RealtimeChannel.on'
+ 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).
+ - 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:
+ - name: Listen to all database changes
isSpotlight: true
js: |
```js
- const { data, error } = await supabase
- .from('countries')
- .select('name, id, population_range_millions')
- .rangeGte('population_range_millions', '[150, 250]')
+ supabase
+ .channel('*')
+ .on('postgres_changes', { event: '*', schema: '*' }, payload => {
+ console.log('Change received!', payload)
+ })
+ .subscribe()
```
- - name: With `update()`
+ - name: Listening to a specific table
js: |
```js
- const { data, error } = await supabase
- .from('countries')
- .update({ name: 'Mordor' })
- .rangeGte('population_range_millions', '[150, 250]')
+ supabase
+ .channel('public:countries')
+ .on('postgres_changes', { event: '*', schema: 'public', table: 'countries' }, payload => {
+ console.log('Change received!', payload)
+ })
+ .subscribe()
```
- - name: With `delete()`
+ - name: Listening to inserts
js: |
```js
- const { data, error } = await supabase
- .from('countries')
- .delete()
- .rangeGte('population_range_millions', '[150, 250]')
+ supabase
+ .channel('public:countries')
+ .on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'countries' }, payload => {
+ console.log('Change received!', payload)
+ })
+ .subscribe()
+ ```
+ - name: Listening to updates
+ description: |
+ By default, Supabase will send only the updated record. If you want to receive the previous values as well you can
+ enable full replication for the table you are listening to:
+
+ ```sql
+ alter table "your_table" replica identity full;
```
- - name: With `rpc()`
js: |
```js
- // Only valid if the Postgres function returns a table type.
- const { data, error } = await supabase
- .rpc('echo_all_countries')
- .rangeGte('population_range_millions', '[150, 250]')
+ supabase
+ .channel('public:countries')
+ .on('postgres_changes', { event: 'UPDATE', schema: 'public', table: 'countries' }, payload => {
+ console.log('Change received!', payload)
+ })
+ .subscribe()
```
+ - name: Listening to deletes
+ description: |
+ By default, Supabase does not send deleted records. If you want to receive the deleted record you can
+ enable full replication for the table you are listening too:
- .rangeLte():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.rangeLte'
- examples:
- - name: With `select()`
- isSpotlight: true
- js: |
- ```js
- const { data, error } = await supabase
- .from('countries')
- .select('name, id, population_range_millions')
- .rangeLte('population_range_millions', '[150, 250]')
+ ```sql
+ alter table "your_table" replica identity full;
```
- - name: With `update()`
js: |
```js
- const { data, error } = await supabase
- .from('countries')
- .update({ name: 'Mordor' })
- .rangeLte('population_range_millions', '[150, 250]')
+ supabase
+ .channel('public:countries')
+ .on('postgres_changes', { event: 'DELETE', schema: 'public', table: 'countries' }, payload => {
+ console.log('Change received!', payload)
+ })
+ .subscribe()
```
- - name: With `delete()`
+ - name: Listening to multiple events
+ description: You can chain listeners if you want to listen to multiple events for each table.
js: |
```js
- const { data, error } = await supabase
- .from('countries')
- .delete()
- .rangeLte('population_range_millions', '[150, 250]')
+ supabase
+ .channel('public:countries')
+ .on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'countries' }, handleRecordInserted)
+ .on('postgres_changes', { event: 'DELETE', schema: 'public', table: 'countries' }, handleRecordDeleted)
+ .subscribe()
```
- - name: With `rpc()`
+ - name: Listening to row level changes
+ description: 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.
+ notes: |
+ - ``eq`` filter works with all database types as under the hood, it's casting both the filter value and the database value to the correct type and then comparing them.
js: |
```js
- // Only valid if the Postgres function returns a table type.
- const { data, error } = await supabase
- .rpc('echo_all_countries')
- .rangeLte('population_range_millions', '[150, 250]')
+ supabase
+ .channel('public:countries:id=eq.200')
+ .on('postgres_changes', { event: 'UPDATE', schema: 'public', table: 'countries', filter: 'id=eq.200' }, handleRecordUpdated)
+ .subscribe()
```
- .rangeAdjacent():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.rangeAdjacent'
+ getChannels():
+ title: 'getChannels()'
+ $ref: '@supabase/supabase-js.index.SupabaseClient.getChannels'
examples:
- - name: With `select()`
+ - name: Get all channels
isSpotlight: true
js: |
```js
- const { data, error } = await supabase
- .from('countries')
- .select('name, id, population_range_millions')
- .rangeAdjacent('population_range_millions', '[70, 185]')
+ const channels = supabase.getChannels()
```
- - name: With `update()`
+
+ removeChannel():
+ title: 'removeChannel()'
+ $ref: '@supabase/supabase-js.index.SupabaseClient.removeChannel'
+ 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:
+ - name: Removes a channel
+ isSpotlight: true
js: |
```js
- const { data, error } = await supabase
- .from('countries')
- .update({ name: 'Mordor' })
- .rangeAdjacent('population_range_millions', '[70, 185]')
+ supabase.removeChannel(myChannel)
```
- - name: With `delete()`
+
+ removeAllChannels():
+ title: 'removeAllChannels()'
+ $ref: '@supabase/supabase-js.index.SupabaseClient.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:
+ - name: Remove all channels
+ isSpotlight: true
js: |
```js
- const { data, error } = await supabase
- .from('countries')
- .delete()
- .rangeAdjacent('population_range_millions', '[70, 185]')
+ supabase.removeAllChannels()
```
- - name: With `rpc()`
+
+ storage.listBuckets():
+ title: 'listBuckets()'
+ $ref: '@supabase/storage-js.packages/StorageBucketApi.default.listBuckets'
+ notes: |
+ - RLS policy permissions required:
+ - `buckets` table permissions: `select`
+ - `objects` table permissions: none
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ examples:
+ - name: List buckets
+ isSpotlight: true
js: |
```js
- // Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_countries')
- .rangeAdjacent('population_range_millions', '[70, 185]')
+ .storage
+ .listBuckets()
```
- .overlaps():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.overlaps'
+ storage.getBucket():
+ title: 'getBucket()'
+ $ref: '@supabase/storage-js.packages/StorageBucketApi.default.getBucket'
notes: |
- - `.overlaps()` can work on array columns or range columns.
-
- ```js
- .overlaps('arraycol',["a","b"]) // You can use a javascript array for an array column
- .overlaps('arraycol','{"a","b"}') // You can use a string with Postgres array {} for array column.
- .overlaps('rangecol','(1,2]') // Use Postgres range syntax for range column.
- .overlaps('rangecol',`(${arr}]`) // You can insert an array into a string.
- ```
+ - RLS policy permissions required:
+ - `buckets` table permissions: `select`
+ - `objects` table permissions: none
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
examples:
- - name: With `select()`
+ - name: Get bucket
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('countries')
- .select('name, id, main_exports')
- .overlaps('main_exports', ['computers', 'minerals'])
- ```
- - name: With `update()`
- js: |
- ```js
- let countries = await supabase
- .from('countries')
- .update({ name: 'Mordor' })
- .overlaps('main_exports', ['computers', 'minerals'])
+ .storage
+ .getBucket('avatars')
```
- - name: With `delete()`
+
+ storage.createBucket():
+ title: 'createBucket()'
+ $ref: '@supabase/storage-js.packages/StorageBucketApi.default.createBucket'
+ notes: |
+ - RLS policy permissions required:
+ - `buckets` table permissions: `insert`
+ - `objects` table permissions: none
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ examples:
+ - name: Create bucket
+ isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('countries')
- .delete()
- .overlaps('main_exports', ['computers', 'minerals'])
+ .storage
+ .createBucket('avatars', { public: false })
```
- - name: With `rpc()`
+
+ storage.emptyBucket():
+ title: 'emptyBucket()'
+ $ref: '@supabase/storage-js.packages/StorageBucketApi.default.emptyBucket'
+ notes: |
+ - RLS policy permissions required:
+ - `buckets` table permissions: `select`
+ - `objects` table permissions: `select` and `delete`
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ examples:
+ - name: Empty bucket
+ isSpotlight: true
js: |
```js
- // Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_countries')
- .overlaps('main_exports', ['computers', 'minerals'])
+ .storage
+ .emptyBucket('avatars')
```
-
- .textSearch():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.textSearch'
+ storage.updateBucket():
+ title: 'updateBucket()'
+ $ref: '@supabase/storage-js.packages/StorageBucketApi.default.updateBucket'
+ notes: |
+ - RLS policy permissions required:
+ - `buckets` table permissions: `update`
+ - `objects` table permissions: none
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
examples:
- - name: Text search
+ - name: Update bucket
+ isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('quotes')
- .select('catchphrase')
- .textSearch('catchphrase', `'fat' & 'cat'`, {
- config: 'english'
+ .storage
+ .updateBucket('avatars', { public: false })
+ ```
+
+ storage.deleteBucket():
+ title: 'deleteBucket()'
+ $ref: '@supabase/storage-js.packages/StorageBucketApi.default.deleteBucket'
+ notes: |
+ - RLS policy permissions required:
+ - `buckets` table permissions: `select` and `delete`
+ - `objects` table permissions: none
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ examples:
+ - name: Delete bucket
+ isSpotlight: true
+ js: |
+ ```js
+ const { data, error } = await supabase
+ .storage
+ .deleteBucket('avatars')
+ ```
+
+ storage.from.upload():
+ title: 'from.upload()'
+ $ref: '@supabase/storage-js.packages/StorageFileApi.default.upload'
+ notes: |
+ - RLS policy permissions required:
+ - `buckets` table permissions: none
+ - `objects` table permissions: `insert`
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ - For React Native, using either `Blob`, `File` or `FormData` does not work as intended. Upload file using `ArrayBuffer` from base64 file data instead, see example below.
+ examples:
+ - name: Upload file
+ isSpotlight: true
+ js: |
+ ```js
+ const avatarFile = event.target.files[0]
+ const { data, error } = await supabase
+ .storage
+ .from('avatars')
+ .upload('public/avatar1.png', avatarFile, {
+ cacheControl: '3600',
+ upsert: false
})
```
- - name: Basic normalization
- description: Uses PostgreSQL's `plainto_tsquery` function.
+ - name: Upload file using `ArrayBuffer` from base64 file data
js: |
```js
+ import { decode } from 'base64-arraybuffer'
+
const { data, error } = await supabase
- .from('quotes')
- .select('catchphrase')
- .textSearch('catchphrase', `'fat' & 'cat'`, {
- type: 'plain',
- config: 'english'
+ .storage
+ .from('avatars')
+ .upload('public/avatar1.png', decode('base64FileData'), {
+ contentType: 'image/png'
})
```
- - name: Full normalization
- description: Uses PostgreSQL's `phraseto_tsquery` function.
+
+ storage.from.update():
+ title: 'from.update()'
+ $ref: '@supabase/storage-js.packages/StorageFileApi.default.update'
+ notes: |
+ - RLS policy permissions required:
+ - `buckets` table permissions: none
+ - `objects` table permissions: `update` and `select`
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ - For React Native, using either `Blob`, `File` or `FormData` does not work as intended. Update file using `ArrayBuffer` from base64 file data instead, see example below.
+ examples:
+ - name: Update file
+ isSpotlight: true
js: |
```js
+ const avatarFile = event.target.files[0]
const { data, error } = await supabase
- .from('quotes')
- .select('catchphrase')
- .textSearch('catchphrase', `'fat' & 'cat'`, {
- type: 'phrase',
- config: 'english'
+ .storage
+ .from('avatars')
+ .update('public/avatar1.png', avatarFile, {
+ cacheControl: '3600',
+ upsert: false
})
```
- - name: Websearch
- description: |
- Uses PostgreSQL's `websearch_to_tsquery` function.
- This function will never raise syntax errors, which makes it possible to use raw user-supplied input for search, and can be used
- with advanced operators.
+ - name: Update file using `ArrayBuffer` from base64 file data
+ js: |
+ ```js
+ import {decode} from 'base64-arraybuffer'
- - `unquoted text`: text not inside quote marks will be converted to terms separated by & operators, as if processed by plainto_tsquery.
- - `"quoted text"`: text inside quote marks will be converted to terms separated by <-> operators, as if processed by phraseto_tsquery.
- - `OR`: the word “or” will be converted to the | operator.
- - `-`: a dash will be converted to the ! operator.
+ const { data, error } = await supabase
+ .storage
+ .from('avatars')
+ .update('public/avatar1.png', decode('base64FileData'), {
+ contentType: 'image/png'
+ })
+ ```
+ storage.from.move():
+ title: 'from.move()'
+ $ref: '@supabase/storage-js.packages/StorageFileApi.default.move'
+ notes: |
+ - RLS policy permissions required:
+ - `buckets` table permissions: none
+ - `objects` table permissions: `update` and `select`
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ examples:
+ - name: Move file
+ isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('quotes')
- .select('catchphrase')
- .textSearch('catchphrase', `'fat or cat'`, {
- type: 'websearch',
- config: 'english'
- })
+ .storage
+ .from('avatars')
+ .move('public/avatar1.png', 'private/avatar2.png')
```
- .filter():
- $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.filter'
+ storage.from.copy():
+ title: 'from.copy()'
+ $ref: '@supabase/storage-js.packages/StorageFileApi.default.copy'
notes: |
- - `.filter()` expects you to use the raw [PostgREST syntax](https://postgrest.org/en/stable/api.html#horizontal-filtering-rows) for the filter names and values, so it should only be used as an escape hatch in case other filters don't work.
- ```js
- .filter('arraycol','cs','{"a","b"}') // Use Postgres array {} for array column and 'cs' for contains.
- .filter('rangecol','cs','(1,2]') // Use Postgres range syntax for range column.
- .filter('id','in','(6,7)') // Use Postgres list () for in filter.
- .filter('id','in',`(${arr})`) // You can insert a javascript array.
- ```
+ - RLS policy permissions required:
+ - `buckets` table permissions: none
+ - `objects` table permissions: `insert` and `select`
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
examples:
- - name: With `select()`
+ - name: Copy file
isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .select('name, country_id')
- .filter('name', 'in', '("Paris","Tokyo")')
+ .storage
+ .from('avatars')
+ .copy('public/avatar1.png', 'private/avatar2.png')
```
- - name: With `update()`
+
+ storage.from.createSignedUrl():
+ title: 'from.createSignedUrl()'
+ $ref: '@supabase/storage-js.packages/StorageFileApi.default.createSignedUrl'
+ notes: |
+ - RLS policy permissions required:
+ - `buckets` table permissions: none
+ - `objects` table permissions: `select`
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ examples:
+ - name: Create Signed URL
+ isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .update({ name: 'Mordor' })
- .filter('name', 'in', '("Paris","Tokyo")')
+ .storage
+ .from('avatars')
+ .createSignedUrl('folder/avatar1.png', 60)
```
- - name: With `delete()`
+
+ storage.from.createSignedUrls():
+ title: 'from.createSignedUrls()'
+ $ref: '@supabase/storage-js.packages/StorageFileApi.default.createSignedUrls'
+ notes: |
+ - RLS policy permissions required:
+ - `buckets` table permissions: none
+ - `objects` table permissions: `select`
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ examples:
+ - name: Create Signed URLs
+ isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .delete()
- .filter('name', 'in', '("Paris","Tokyo")')
+ .storage
+ .from('avatars')
+ .createSignedUrls(['folder/avatar1.png', 'folder/avatar2.png'], 60)
```
- - name: With `rpc()`
+
+ storage.from.getPublicUrl():
+ title: 'from.getPublicUrl()'
+ $ref: '@supabase/storage-js.packages/StorageFileApi.default.getPublicUrl'
+ notes: |
+ - The bucket needs to be set to public, either via [updateBucket()](/docs/reference/javascript/storage-updatebucket) or by going to Storage on [app.supabase.com](https://app.supabase.com), clicking the overflow menu on a bucket and choosing "Make public"
+ - RLS policy permissions required:
+ - `buckets` table permissions: none
+ - `objects` table permissions: none
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ examples:
+ - name: Returns the URL for an asset in a public bucket
+ isSpotlight: true
+ js: |
+ ```js
+ const { data } = supabase
+ .storage
+ .from('public-bucket')
+ .getPublicUrl('folder/avatar1.png')
+ ```
+
+ storage.from.download():
+ title: 'from.download()'
+ $ref: '@supabase/storage-js.packages/StorageFileApi.default.download'
+ notes: |
+ - RLS policy permissions required:
+ - `buckets` table permissions: none
+ - `objects` table permissions: `select`
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ examples:
+ - name: Download file
+ isSpotlight: true
js: |
```js
- // Only valid if the Postgres function returns a table type.
const { data, error } = await supabase
- .rpc('echo_all_cities')
- .filter('name', 'in', '("Paris","Tokyo")')
+ .storage
+ .from('avatars')
+ .download('folder/avatar1.png')
```
- - name: Filter embedded resources
+
+ storage.from.remove():
+ title: 'from.remove()'
+ $ref: '@supabase/storage-js.packages/StorageFileApi.default.remove'
+ notes: |
+ - RLS policy permissions required:
+ - `buckets` table permissions: none
+ - `objects` table permissions: `delete` and `select`
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ examples:
+ - name: Delete file
+ isSpotlight: true
js: |
```js
const { data, error } = await supabase
- .from('cities')
- .select('name, countries ( name )')
- .filter('countries.name', 'in', '("France","Japan")')
+ .storage
+ .from('avatars')
+ .remove(['folder/avatar1.png'])
+ ```
+
+ storage.from.list():
+ title: 'from.list()'
+ $ref: '@supabase/storage-js.packages/StorageFileApi.default.list'
+ notes: |
+ - RLS policy permissions required:
+ - `buckets` table permissions: none
+ - `objects` table permissions: `select`
+ - Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
+ examples:
+ - name: List files in a bucket
+ isSpotlight: true
+ js: |
+ ```js
+ const { data, error } = await supabase
+ .storage
+ .from('avatars')
+ .list('folder', {
+ limit: 100,
+ offset: 0,
+ sortBy: { column: 'name', order: 'asc' },
+ })
+ ```
+ - name: Search files in a bucket
+ js: |
+ ```js
+ const { data, error } = await supabase
+ .storage
+ .from('avatars')
+ .list('folder', {
+ limit: 100,
+ offset: 0,
+ sortBy: { column: 'name', order: 'asc' },
+ search: 'jon'
+ })
```