mirror of
https://github.com/supabase/supabase.git
synced 2026-06-24 09:55:17 +08:00
119 lines
1.8 KiB
Plaintext
119 lines
1.8 KiB
Plaintext
---
|
|
id: rpc
|
|
title: "Stored Procedures: rpc()"
|
|
slug: rpc
|
|
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/dart.yml
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
import TabsPanel from '@theme/TabsPanel';
|
|
|
|
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
|
|
defaultActiveId="dart"
|
|
groupId="reference/dart"
|
|
values={[{ label: 'Dart', value: 'dart' }]}>
|
|
|
|
<TabsPanel id="dart" label="dart">
|
|
|
|
```dart
|
|
final res = await supabase
|
|
.rpc('hello_world')
|
|
.execute();
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
### Call a stored procedure
|
|
|
|
This is an example invoking a stored procedure.
|
|
|
|
<Tabs
|
|
defaultActiveId="dart"
|
|
groupId="reference/dart"
|
|
values={[{ label: 'Dart', value: 'dart' }]}>
|
|
|
|
<TabsPanel id="dart" label="dart">
|
|
|
|
```dart
|
|
final res = await supabase
|
|
.rpc('hello_world')
|
|
.execute();
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs>
|
|
|
|
### With Parameters
|
|
|
|
|
|
|
|
<Tabs
|
|
defaultActiveId="dart"
|
|
groupId="reference/dart"
|
|
values={[{ label: 'Dart', value: 'dart' }]}>
|
|
|
|
<TabsPanel id="dart" label="dart">
|
|
|
|
```dart
|
|
final res = await supabase
|
|
.rpc('echo_city', params: { 'name': 'The Shire' })
|
|
.execute();
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs>
|
|
|
|
### With count option
|
|
|
|
You can specify a count option to get the row count along with your data.
|
|
Allowed values for count option are `exact`, `planned` and `estimated`.
|
|
|
|
|
|
<Tabs
|
|
defaultActiveId="dart"
|
|
groupId="reference/dart"
|
|
values={[{ label: 'Dart', value: 'dart' }]}>
|
|
|
|
<TabsPanel id="dart" label="dart">
|
|
|
|
```dart
|
|
final res = await supabase
|
|
.rpc('hello_world')
|
|
.execute(count: CountOption.exact);
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs> |