Files
supabase/web/docs/client/rpc.mdx
T
ykdojo 0ae83a337e Test generating docs
I tried running npm run gen:supabase, and this is the result.
2020-12-22 12:48:50 -08:00

229 lines
3.3 KiB
Plaintext

---
id: rpc
title: "Stored Procedures: rpc()"
slug: rpc
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
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.
It's especially useful when the logic rarely changes - like password resets and updates.
<Tabs
defaultValue="js"
groupId="libraries"
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
<TabItem value="js">
```js
const { data, error } = await supabase
.rpc('hello_world')
}
```
</TabItem>
<TabItem value="py">
```py
# Not yet implemented
```
</TabItem>
</Tabs>
## Parameters
<ul className="method-list-group">
<li className="method-list-item">
<h4 className="method-list-item-label">
<span className="method-list-item-label-name">
fn
</span>
<span className="method-list-item-label-badge required">
required
</span>
<span className="method-list-item-validation">
<code>string</code>
</span>
</h4>
<div class="method-list-item-description">
The function name to call.
</div>
</li>
<li className="method-list-item">
<h4 className="method-list-item-label">
<span className="method-list-item-label-name">
params
</span>
<span className="method-list-item-label-badge false">
optional
</span>
<span className="method-list-item-validation">
<code>undefined</code> | <code>object</code>
</span>
</h4>
<div class="method-list-item-description">
The parameters to pass to the function call.
</div>
</li>
</ul>
## Examples
### Call a stored procedure
This is an example invoking a stored procedure.
<Tabs
defaultValue="js"
groupId="libraries"
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
<TabItem value="js">
```js
const { data, error } = await supabase
.rpc('hello_world')
}
```
</TabItem>
<TabItem value="py">
```py
# Not yet implemented
```
</TabItem>
</Tabs>
### With Parameters
<Tabs
defaultValue="js"
groupId="libraries"
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
<TabItem value="js">
```js
const { data, error } = await supabase
.rpc('echo_city', { name: 'The Shire' })
}
```
</TabItem>
<TabItem value="py">
```py
# Not yet implemented
```
</TabItem>
</Tabs>
### Bulk call
<Tabs
defaultValue="js"
groupId="libraries"
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
<TabItem value="js">
```js
const { data, error } = await supabase
.rpc('echo_city', [
{ name: 'The Shire' },
{ name: 'Mordor' }
])
}
```
</TabItem>
<TabItem value="py">
```py
# Not yet implemented
```
</TabItem>
</Tabs>
### With filters.
Stored procedures that return tables can also be combined with
[Modifiers](/docs/client/using-modifiers) and
[Filters](/docs/client/using-filters).
<Tabs
defaultValue="js"
groupId="libraries"
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
<TabItem value="js">
```js
const { data, error } = await supabase
.rpc('echo_all_cities')
.eq('name', 'The Shire')
```
</TabItem>
<TabItem value="py">
```py
# Not yet implemented
```
</TabItem>
</Tabs>