Skip to content

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

RPC examples for #21 plus minor clean ups on documentation.

Angelico0926fb6b45c1
diff --git a/web/docs/common/filters/eq.mdx b/web/docs/common/filters/eq.mdx
index 3607c2417cf..1eb458f33d5 100644
--- a/web/docs/common/filters/eq.mdx
+++ b/web/docs/common/filters/eq.mdx
@@ -1,5 +1,6 @@
import Collapsable from '../../../src/components/Collapsable'
+#### General form
<!-- prettier-ignore -->
```js {3}
supabase
diff --git a/web/docs/common/filters/filter.mdx b/web/docs/common/filters/filter.mdx
index aec385f123a..95df65ef5f4 100644
--- a/web/docs/common/filters/filter.mdx
+++ b/web/docs/common/filters/filter.mdx
@@ -1,5 +1,6 @@
import Collapsable from '../../../src/components/Collapsable'
+#### General form
<!-- prettier-ignore -->
```js {3}
supabase
diff --git a/web/docs/common/filters/gt.mdx b/web/docs/common/filters/gt.mdx
index 8470390ad04..bb43aa8bc2e 100644
--- a/web/docs/common/filters/gt.mdx
+++ b/web/docs/common/filters/gt.mdx
@@ -1,5 +1,6 @@
import Collapsable from '../../../src/components/Collapsable'
+#### General form
<!-- prettier-ignore -->
```js {3}
supabase
diff --git a/web/docs/common/filters/gte.mdx b/web/docs/common/filters/gte.mdx
index ed5eae2d38f..275dba59bb8 100644
--- a/web/docs/common/filters/gte.mdx
+++ b/web/docs/common/filters/gte.mdx
@@ -1,5 +1,6 @@
import Collapsable from '../../../src/components/Collapsable'
+#### General form
<!-- prettier-ignore -->
```js {3}
supabase
diff --git a/web/docs/common/filters/ilike.mdx b/web/docs/common/filters/ilike.mdx
index 0fe84b25193..1d2c1ab8c69 100644
--- a/web/docs/common/filters/ilike.mdx
+++ b/web/docs/common/filters/ilike.mdx
@@ -1,5 +1,6 @@
import Collapsable from '../../../src/components/Collapsable'
+#### General form
<!-- prettier-ignore -->
```js {3}
supabase
diff --git a/web/docs/common/filters/in.mdx b/web/docs/common/filters/in.mdx
index d59a5981a73..0bcb2385ab6 100644
--- a/web/docs/common/filters/in.mdx
+++ b/web/docs/common/filters/in.mdx
@@ -1,5 +1,6 @@
import Collapsable from '../../../src/components/Collapsable'
+#### General form
<!-- prettier-ignore -->
```js {3}
supabase
diff --git a/web/docs/common/filters/is.mdx b/web/docs/common/filters/is.mdx
index 821c832333d..318ece96eec 100644
--- a/web/docs/common/filters/is.mdx
+++ b/web/docs/common/filters/is.mdx
@@ -1,5 +1,6 @@
import Collapsable from '../../../src/components/Collapsable'
+#### General form
<!-- prettier-ignore -->
```js {3}
supabase
diff --git a/web/docs/common/filters/like.mdx b/web/docs/common/filters/like.mdx
index e8d288e3fcb..b820607910e 100644
--- a/web/docs/common/filters/like.mdx
+++ b/web/docs/common/filters/like.mdx
@@ -1,5 +1,6 @@
import Collapsable from '../../../src/components/Collapsable'
+#### General form
<!-- prettier-ignore -->
```js {3}
supabase
diff --git a/web/docs/common/filters/lt.mdx b/web/docs/common/filters/lt.mdx
index c35aba41fb5..811cd03d57c 100644
--- a/web/docs/common/filters/lt.mdx
+++ b/web/docs/common/filters/lt.mdx
@@ -1,5 +1,6 @@
import Collapsable from '../../../src/components/Collapsable'
+#### General form
<!-- prettier-ignore -->
```js {3}
supabase
diff --git a/web/docs/common/filters/lte.mdx b/web/docs/common/filters/lte.mdx
index 3d6997332d6..84fc9f146d0 100644
--- a/web/docs/common/filters/lte.mdx
+++ b/web/docs/common/filters/lte.mdx
@@ -1,5 +1,6 @@
import Collapsable from '../../../src/components/Collapsable'
+#### General form
<!-- prettier-ignore -->
```js {3}
supabase
diff --git a/web/docs/common/filters/match.mdx b/web/docs/common/filters/match.mdx
index 0d1fff63ec0..05ec07296df 100644
--- a/web/docs/common/filters/match.mdx
+++ b/web/docs/common/filters/match.mdx
@@ -1,5 +1,6 @@
import Collapsable from '../../../src/components/Collapsable'
+#### General form
<!-- prettier-ignore -->
```js {3}
supabase
diff --git a/web/docs/common/filters/not.mdx b/web/docs/common/filters/not.mdx
index 9d2ca22f21c..f3a73c47967 100644
--- a/web/docs/common/filters/not.mdx
+++ b/web/docs/common/filters/not.mdx
@@ -1,5 +1,6 @@
import Collapsable from '../../../src/components/Collapsable'
+#### General form
<!-- prettier-ignore -->
```js {3}
supabase
diff --git a/web/docs/library/examples/delete.js b/web/docs/library/examples/delete.js
index a462656bd7b..e952c764b59 100644
--- a/web/docs/library/examples/delete.js
+++ b/web/docs/library/examples/delete.js
@@ -26,7 +26,7 @@ import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
-const deleteCIty = async () => {
+const deleteCity = async () => {
try {
let cities = await supabase
.from('cities')
@@ -44,7 +44,7 @@ import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
-const deleteCIty = async () => {
+const deleteCity = async () => {
try {
let cities = await supabase
.from('cities')
@@ -62,7 +62,7 @@ import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
-const deleteCIty = async () => {
+const deleteCity = async () => {
try {
let cities = await supabase
.from('cities')
@@ -80,7 +80,7 @@ import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
-const deleteCIty = async () => {
+const deleteCity = async () => {
try {
let cities = await supabase
.from('cities')
@@ -98,7 +98,7 @@ import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
-const deleteCIty = async () => {
+const deleteCity = async () => {
try {
let cities = await supabase
.from('cities')
@@ -116,7 +116,7 @@ import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
-const deleteCIty = async () => {
+const deleteCity = async () => {
try {
let cities = await supabase
.from('cities')
@@ -134,7 +134,7 @@ import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
-const deleteCIty = async () => {
+const deleteCity = async () => {
try {
let cities = await supabase
.from('cities')
@@ -152,7 +152,7 @@ import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
-const deleteCIty = async () => {
+const deleteCity = async () => {
try {
let cities = await supabase
.from('cities')
@@ -170,7 +170,7 @@ import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
-const deleteCIty = async () => {
+const deleteCity = async () => {
try {
let cities = await supabase
.from('cities')
@@ -188,7 +188,7 @@ import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
-const deleteCIty = async () => {
+const deleteCity = async () => {
try {
let cities = await supabase
.from('cities')
@@ -206,7 +206,7 @@ import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
-const deleteCIty = async () => {
+const deleteCity = async () => {
try {
let cities = await supabase
.from('cities')
@@ -224,7 +224,7 @@ import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
-const deleteCIty = async () => {
+const deleteCity = async () => {
try {
let cities = await supabase
.from('cities')
diff --git a/web/docs/library/examples/stored.js b/web/docs/library/examples/stored.js
index f60788ab198..9ae4d0f5c2a 100644
--- a/web/docs/library/examples/stored.js
+++ b/web/docs/library/examples/stored.js
@@ -45,10 +45,213 @@ const supabase = createClient('https://world.supabase.co', '1a2b-3c4d-5e6f-7g8h'
const echoCities = async () => {
try{
let cities = await supabase
- .rpc('asian_pacific_countries')
+ .rpc('echo_all_cities')
return cities
} catch (error) {
console.log('Error: ', error)
}
}
`
+export const storedFilterJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const echoCities = async () => {
+ try {
+ let cities = await supabase
+ .rpc('echo_all_cities')
+ .filter({'name', 'eq', 'Paris'})
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const storedMatchJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const echoCities = async () => {
+ try {
+ let cities = await supabase
+ .rpc('echo_all_cities')
+ .match({name: 'Beijing', country_id: 156})
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const storedEqJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const echoCities = async () => {
+ try {
+ let cities = await supabase
+ .rpc('echo_all_cities')
+ .eq('name', 'San Francisco')
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const storedGtJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const echoCities = async () => {
+ try {
+ let cities = await supabase
+ .rpc('echo_all_cities')
+ .gt('country_id', 250)
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const storedLtJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const echoCities = async () => {
+ try {
+ let cities = await supabase
+ .rpc('echo_all_cities')
+ .lt('country_id', 250)
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const storedGteJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const echoCities = async () => {
+ try {
+ let cities = await supabase
+ .rpc('echo_all_cities')
+ .gte('country_id', 250)
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const storedLteJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const echoCities = async () => {
+ try {
+ let cities = await supabase
+ .rpc('echo_all_cities')
+ .lte('country_id', 250)
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const storedLikeJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const echoCities = async () => {
+ try {
+ let cities = await supabase
+ .rpc('echo_all_cities')
+ .like('name', '%la%')
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const storedIlikeJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const echoCities = async () => {
+ try {
+ let cities = await supabase
+ .rpc('echo_all_cities')
+ .ilike('name', '%la%')
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const storedIsJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const echoCities = async () => {
+ try {
+ let cities = await supabase
+ .rpc('echo_all_cities')
+ .is('name', null)
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const storedInJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const echoCities = async () => {
+ try {
+ let cities = await supabase
+ .rpc('echo_all_cities')
+ .in('name', ['Rio de Janeiro', 'San Francisco'])
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const storedNotJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const echoCities = async () => {
+ try {
+ let cities = await supabase
+ .rpc('echo_all_cities')
+ .not('name', 'Lagos')
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
diff --git a/web/docs/library/get.mdx b/web/docs/library/get.mdx
index 9bae9c789c0..2285b81d86c 100644
--- a/web/docs/library/get.mdx
+++ b/web/docs/library/get.mdx
@@ -39,7 +39,7 @@ import { getSimpleJs,
### Getting your data
<CustomCodeBlock
- header="Shows how to get all countries from our public 'world' database"
+ header="Shows how to get all cities from our public 'world' database"
js={getSimpleJs}
jsHighlight="{7-9}"
response={`{
diff --git a/web/docs/library/stored-procedures.mdx b/web/docs/library/stored-procedures.mdx
index a08910ee9ea..941b9c1c9e3 100644
--- a/web/docs/library/stored-procedures.mdx
+++ b/web/docs/library/stored-procedures.mdx
@@ -9,11 +9,27 @@ import CommonFilters from '../common/CommonFilters'
import CommonResponses from '../common/CommonResponses.mdx'
import DummyData from '../common/DummyData.mdx'
import CustomCodeBlock from '../../src/components/CustomCodeBlock'
-import { storedSingleJs, storedBulkJs, storedReadingJs } from './examples/stored'
-
-You can call stored procedures as a "Remote Procedure Call".
-
-That's a fancy way of saying that you can put some logic into your database then call it from anywhere.
+import {
+ storedSingleJs,
+ storedBulkJs,
+ storedReadingJs,
+ storedFilterJs,
+ storedMatchJs,
+ storedEqJs,
+ storedGtJs,
+ storedLtJs,
+ storedGteJs,
+ storedLteJs,
+ storedLikeJs,
+ storedIlikeJs,
+ storedIsJs,
+ storedInJs,
+ storedNotJs,
+} from './examples/stored'
+
+You can call stored procedures as a "Remote Procedure Call".
+
+That's a fancy way of saying that you can put some logic into your database then call it from anywhere.
This is especially useful when the logic rarely changes - like password resets and updates.
<DummyData />
@@ -55,7 +71,7 @@ This example would call a the same stored procedure above (twice), but it will a
`}
/>
-### Reading data
+### Reading data
This example shows how to call a stored function that returns a table type response:
@@ -65,8 +81,12 @@ This example shows how to call a stored function that returns a table type respo
jsHighlight="{7-8}"
response={`{
"body": [
- {"id": 156, "name": "China", "iso2": "CN", "continent": "Asia"},
- {"id": 554, "name": "New Zealand", "iso2": "NZ", "continent": "Oceania"}
+ { "name": "Rio de Janeiro", "country_id": 76 },
+ { "name": "Beijing", "country_id": 156 },
+ { "name": "Paris", "country_id": 250 },
+ { "name": "Auckland", "country_id": 554 },
+ { "name": "Lagos", "country_id": 556 },
+ { "name": "San Francisco", "country_id": 840 }
],
"status": 200,
"statusCode": 200,
@@ -78,60 +98,283 @@ This example shows how to call a stored function that returns a table type respo
## Reference
### `rpc()`
+
```js {2}
-supabase
+supabase
.rpc(functionName, functionParameters)
```
#### `functionName: string`
+
Name of stored function in the database.
#### `functionParameters: { object? | array? }`
+
Parameters to be passed to the stored function.
---
## Filtering
-If the stored procedure returns a table, you can also apply filters to the response.
### `filter()`
+
+<CustomCodeBlock
+ header="Shows how to use filter( ) with rpc( )"
+ js={storedFilterJs}
+ jsHighlight="{9}"
+ response={`{
+ "body": [
+ { "name": "Paris", "country_id": 250 },
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='filter'/>
### `match()`
+
+<CustomCodeBlock
+ header="Shows how to use match( ) with rpc( )"
+ js={storedMatchJs}
+ jsHighlight="{9}"
+ response={`{
+ "body": [
+ { "name": "Beijing", "country_id": 156 },
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='match'/>
### `eq()`
+
+<CustomCodeBlock
+ header="Shows how to use eq( ) with rpc( )"
+ js={storedEqJs}
+ jsHighlight="{9}"
+ response={`{
+ "body": [
+ { "name": "San Francisco", "country_id": 840 },
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='eq'/>
### `gt()`
+
+<CustomCodeBlock
+ header="Shows how to use gt( ) with rpc( )"
+ js={storedGtJs}
+ jsHighlight="{9}"
+ response={`{
+ "body": [
+ { "name": "Auckland", "country_id": 554 },
+ { "name": "Lagos", "country_id": 556 },
+ { "name": "San Francisco", "country_id": 840 }
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='gt'/>
### `lt()`
+
+<CustomCodeBlock
+ header="Shows how to use lt( ) with rpc( )"
+ js={storedLtJs}
+ jsHighlight="{9}"
+ response={`{
+ "body": [
+ { "name": "Rio de Janeiro", "country_id": 76 },
+ { "name": "Beijing", "country_id": 156 }
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='lt'/>
### `gte()`
+
+<CustomCodeBlock
+ header="Shows how to use gte( ) with rpc( )"
+ js={storedGteJs}
+ jsHighlight="{9}"
+ response={`{
+ "body": [
+ { "name": "Paris", "country_id": 250 },
+ { "name": "Auckland", "country_id": 554 },
+ { "name": "Lagos", "country_id": 556 },
+ { "name": "San Francisco", "country_id": 840 }
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='gte'/>
### `lte()`
+
+<CustomCodeBlock
+ header="Shows how to use lte( ) with rpc( )"
+ js={storedLteJs}
+ jsHighlight="{9}"
+ response={`{
+ "body": [
+ { "name": "Rio de Janeiro", "country_id": 76 },
+ { "name": "Beijing", "country_id": 156 },
+ { "name": "Paris", "country_id": 250 }
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='lte'/>
### `like()`
+
+<CustomCodeBlock
+ header="Shows how to use like( ) with rpc( )"
+ js={storedLikeJs}
+ jsHighlight="{9}"
+ response={`{
+ "body": [
+ { "name": "Auckland", "country_id": 554 },
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='like'/>
### `ilike()`
+
+<CustomCodeBlock
+ header="Shows how to use ilike( ) with rpc( )"
+ js={storedIlikeJs}
+ jsHighlight="{9}"
+ response={`{
+ "body": [
+ { "name": "Auckland", "country_id": 554 },
+ { "name": "Lagos", "country_id": 556 },
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='ilike'/>
### `is()`
+
+<CustomCodeBlock
+ header="Shows how to use is( ) with rpc( )"
+ js={storedIsJs}
+ jsHighlight="{9}"
+ response={`{
+ "body": [
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='is'/>
### `in()`
+
+<CustomCodeBlock
+ header="Shows how to use in( ) with rpc( )"
+ js={storedInJs}
+ jsHighlight="{9}"
+ response={`{
+ "body": [
+ { "name": "Rio de Janeiro", "country_id": 76 },
+ { "name": "San Francisco", "country_id": 840 }
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='in'/>
### `not()`
+
+<CustomCodeBlock
+ header="Shows how to use not( ) with rpc( )"
+ js={storedNotJs}
+ jsHighlight="{9}"
+ response={`{
+ "body": [
+ { "name": "Rio de Janeiro", "country_id": 76 },
+ { "name": "Beijing", "country_id": 156 },
+ { "name": "Paris", "country_id": 250 },
+ { "name": "Auckland", "country_id": 554 },
+ { "name": "Lagos", "country_id": 556 },
+ { "name": "San Francisco", "country_id": 840 }
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='not'/>
## Responses
+#### 200 OK
+Successful request
+
#### 201 Created
Successful