Skip to content

Commit

Permalink
Merge branch 'main' into showcase
Browse files Browse the repository at this point in the history
  • Loading branch information
BeeBombshell committed Jun 7, 2024
2 parents 1124ffc + 2756f99 commit b28669a
Show file tree
Hide file tree
Showing 8 changed files with 920 additions and 10 deletions.
14 changes: 13 additions & 1 deletion pages/tutorials.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Step by step guided tutorial for powerful usecases and examples.
>
<>![Notion Connection preview](../public/tutorial/notionOG.png)</>
</ShowcaseCard>
<ShowcaseCard
<ShowcaseCard
title='Vector Database'
href='./tutorials/vector-applications'
onClick={() => {
Expand All @@ -130,6 +130,18 @@ Step by step guided tutorial for powerful usecases and examples.
>
<>![Vector Database Applications preview](../public/tutorial/vectorOG.png)</>
</ShowcaseCard>
<ShowcaseCard
title='Supabase Postgres RPC'
href='./tutorials/supabase-rpc'
onClick={() => {
window?.posthog?.capture?.('button_docs_tutorials_selected', {
type: 'button_click',
option_clicked: 'supabase-rpc',
});
}}
>
<>![Supabase Postgres Remote Procedure Call preview](../public/tutorial/supabase-rpc-og.png)</>
</ShowcaseCard>
</Cards>

export const ShowcaseCard = Object.assign(
Expand Down
3 changes: 3 additions & 0 deletions pages/tutorials/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
},
"vector-applications": {
"display": "hidden"
},
"supabase-rpc": {
"display": "hidden"
}
}
81 changes: 81 additions & 0 deletions pages/tutorials/supabase-rpc.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
title: Supabase Postgres RPC
description:
The Supabase Postgres RPC node allows you to call Postgres functions in your Supabase database as Remote Procedure
Calls (RPCs).
---

import { Callout } from 'nextra/components';
import Image from 'next/image';
import supabaseRpcOg from 'public/tutorial/supabase-rpc-og.png';
import supabaseRpc1 from 'public/tutorial/supabase-rpc-1.png';
import supabaseRpc2 from 'public/tutorial/supabase-rpc-2.png';

# Supabase Postgres RPC

The Supabase Postgres RPC node **allows you to call Postgres functions in your Supabase database as Remote Procedure
Calls (RPCs)**. This enables you to execute logic stored in your database from anywhere, making it useful for scenarios
where the logic rarely changes, such as password resets or data updates.

<Image src={supabaseRpcOg} alt='Supabase Postgres RPC' width={1200} />

## Setting up a Supabase Postgres Function

Before you can call a Postgres function using the Supabase Postgres RPC node, you need to set up the function in your
Supabase project. Follow these steps:

- **STEP 1:** Open the SQL editor in your Supabase project.
- **STEP 2:** Use the `CREATE OR REPLACE FUNCTION` statement to define your function.
- **STEP 3:** Specify the function name, parameters, return type, and language (e.g., SQL or plpgsql).
- **STEP 4:** Write the function body between the `$$` delimiters.
- **STEP 5:** Execute the SQL statement to create the function.

<Image src={supabaseRpc1} alt='Supabase Postgres RPC' width={1200} />

### Sample Function

Here's an example of a simple function that takes in the `row_id` as an argument and increments the `lifespan` field by
`1` in the "`Dog Breeds`" table:

```sql
create or replace function getBreed (row_id int)
returns void as
$$
update "Dog Breeds"
set lifespan = lifespan + 1
where id = row_id;
$$
language sql volatile;
```

<Callout>
For more detailed instructions on setting up database functions in Supabase, refer to the dedicated documentation
[here](https://supabase.com/docs/guides/database/functions).
</Callout>

## Invoking the Supabase Postgres Function

Once you have set up the Postgres function in your Supabase project, you can invoke it using the Supabase Postgres RPC
node in your BuildShip workflow. Here are the inputs required by the node:

- **API Key**: Your Supabase API Key. You can obtain this from the API Reference section in your Supabase Project
Dashboard. [Learn more here](/tutorials/supabase-crud#api-key-and-url).

- **API URL**: The URL of your Supabase project. You can find this in the API Reference section of your Supabase Project
Dashboard. [Learn more here](/tutorials/supabase-crud#api-key-and-url).

- **Function Name**: The name of the Postgres function you want to call. For example: `getBreed`.

- **Arguments (optional)**: The arguments to pass to the function, if required. For example, if your function expects a
`row_id` argument, you can provide it as an object:

```json
{
"row_id": 2
}
```

<Image src={supabaseRpc2} alt='Supabase Postgres RPC' width={1200} />

So, in this example, the Supabase Postgres RPC node will call the `getBreed` function in your Supabase database, passing
in `2` as the `row_id` argument. **The response from the function will be returned as the output of the node.**
812 changes: 811 additions & 1 deletion public/other/apps.csv

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions public/other/nodes.csv

Large diffs are not rendered by default.

Binary file added public/tutorial/supabase-rpc-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/tutorial/supabase-rpc-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/tutorial/supabase-rpc-og.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b28669a

Please sign in to comment.