Skip to content

Commit afeb51a

Browse files
thomasgauvinOxyjun
andauthored
Update 3rd party db to include Hyperdrive (#23171)
* Update index.mdx * add hyperdrive to 3rd party integrations * Apply suggestions from code review * Apply suggestions from code review * Update src/content/docs/workers/databases/third-party-integrations/neon.mdx --------- Co-authored-by: Jun Lee <[email protected]>
1 parent dc5e6e0 commit afeb51a

File tree

15 files changed

+229
-102
lines changed

15 files changed

+229
-102
lines changed

src/content/docs/hyperdrive/examples/connect-to-mysql/mysql-database-providers/planetscale.mdx

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,4 @@ import { Render } from "~/components";
1212

1313
This example shows you how to connect Hyperdrive to a [PlanetScale](https://planetscale.com/) MySQL database.
1414

15-
## 1. Allow Hyperdrive access
16-
17-
You can connect Hyperdrive to any existing PlanetScale database by creating a new user and fetching your database connection string.
18-
19-
### Planetscale Dashboard
20-
21-
1. Go to the [**PlanetScale dashboard**](https://app.planetscale.com/) and select the database you wish to connect to.
22-
2. Click **Connect**. Enter `hyperdrive-user` as the password name (or your preferred name) and configure the permissions as desired. Select **Create password**. Note the username and password as they will not be displayed again.
23-
3. Select **Other** as your language or framework. Note down the database host, database name, database username, and password. You will need these to create a database configuration in Hyperdrive.
24-
25-
With the host, database name, username and password, you can now create a Hyperdrive database configuration.
26-
27-
## 2. Create a database configuration
28-
29-
<Render file="create-hyperdrive-config-mysql" />
30-
31-
:::note
32-
33-
When connecting to a Planetscale database with Hyperdrive, you should use a driver like [node-postgres (pg)](/hyperdrive/examples/connect-to-postgres/postgres-drivers-and-libraries/node-postgres/) or [Postgres.js](/hyperdrive/examples/connect-to-postgres/postgres-drivers-and-libraries/postgres-js/) to connect directly to the underlying database instead of the [Planetscale serverless driver](https://planetscale.com/docs/tutorials/planetscale-serverless-driver). Hyperdrive is optimized for database access for Workers and will perform global connection pooling and fast query routing by connecting directly to your database.
34-
35-
:::
36-
37-
<Render file="create-hyperdrive-config-mysql-next-steps" />
15+
<Render file="planetscale-partial" />

src/content/docs/hyperdrive/examples/connect-to-postgres/postgres-database-providers/neon.mdx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,4 @@ import { Render } from "~/components";
1212

1313
This example shows you how to connect Hyperdrive to a [Neon](https://neon.tech/) Postgres database.
1414

15-
## 1. Allow Hyperdrive access
16-
17-
You can connect Hyperdrive to any existing Neon database by creating a new user and fetching your database connection string.
18-
19-
### Neon Dashboard
20-
21-
1. Go to the [**Neon dashboard**](https://console.neon.tech/app/projects) and select the project (database) you wish to connect to.
22-
2. Select **Roles** from the sidebar and select **New Role**. Enter `hyperdrive-user` as the name (or your preferred name) and **copy the password**. Note that the password will not be displayed again: you will have to reset it if you do not save it somewhere.
23-
3. Select **Dashboard** from the sidebar > go to the **Connection Details** pane > ensure you have selected the **branch**, **database** and **role** (for example,`hyperdrive-user`) that Hyperdrive will connect through.
24-
4. Select the `psql` and **uncheck the connection pooling** checkbox. Note down the connection string (starting with `postgres://hyperdrive-user@...`) from the text box.
25-
26-
With both the connection string and the password, you can now create a Hyperdrive database configuration.
27-
28-
## 2. Create a database configuration
29-
30-
<Render file="create-hyperdrive-config" />
31-
32-
:::note
33-
34-
When connecting to a Neon database with Hyperdrive, you should use a driver like [node-postgres (pg)](/hyperdrive/examples/connect-to-postgres/postgres-drivers-and-libraries/node-postgres/) or [Postgres.js](/hyperdrive/examples/connect-to-postgres/postgres-drivers-and-libraries/postgres-js/) to connect directly to the underlying database instead of the [Neon serverless driver](https://neon.tech/docs/serverless/serverless-driver). Hyperdrive is optimized for database access for Workers and will perform global connection pooling and fast query routing by connecting directly to your database.
35-
36-
:::
37-
38-
<Render file="create-hyperdrive-config-next-steps" />
15+
<Render file="neon-partial" />

src/content/docs/hyperdrive/examples/connect-to-postgres/postgres-database-providers/xata.mdx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,4 @@ import { Render } from "~/components";
1212

1313
This example shows you how to connect Hyperdrive to a Xata PostgreSQL database instance.
1414

15-
## 1. Allow Hyperdrive access
16-
17-
You can connect Hyperdrive to any existing Xata database with the default user and password provided by Xata.
18-
19-
### Xata dashboard
20-
21-
To retrieve your connection string from the Xata dashboard:
22-
23-
1. Go to the [**Xata dashboard**](https://app.xata.io/).
24-
2. Select the database you want to connect to.
25-
3. Select **Settings**.
26-
4. Copy the connection string from the `PostgreSQL endpoint` section and add your API key.
27-
28-
## 2. Create a database configuration
29-
30-
<Render file="create-hyperdrive-config" />
31-
<Render file="create-hyperdrive-config-next-steps" />
15+
<Render file="xata-partial" />

src/content/docs/workers/databases/third-party-integrations/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import { DirectoryListing } from "~/components"
1313

1414
Connect to databases by configuring connection strings and credentials as [secrets](/workers/configuration/secrets/) in your Worker.
1515

16-
:::note[Making multiple round trip calls to a centralized database from a Worker?]
16+
:::note[Connecting to a regional database from a Worker?]
1717

1818

19-
If your Worker is making multiple round trip calls to a centralized database, your Worker may be a good fit for Smart Placement. Smart Placement speeds up applications by automatically running your Worker closer to your back-end infrastructure rather than the end user. Learn more about [how Smart Placement works](/workers/configuration/smart-placement/).
19+
If your Worker is connecting to a regional database, you can reduce your query latency by using [Hyperdrive](/hyperdrive) and [Smart Placement](/workers/configuration/smart-placement/) which are both included in any Workers plan. Hyperdrive will pool your databases connections globally across Cloudflare's network. Smart Placement will monitor your application to run your Workers closest to your backend infrastructure when this reduces the latency of your Worker invocations. Learn more about [how Smart Placement works](/workers/configuration/smart-placement/).
2020
:::
2121

2222
## Database credentials

src/content/docs/workers/databases/third-party-integrations/neon.mdx

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
---
22
pcx_content_type: configuration
33
title: Neon
4+
description: Connect Workers to a Neon Postgres database.
45
---
56

6-
import { Render, PackageManagers } from "~/components";
7+
import { Render, PackageManagers, Tabs, TabItem } from "~/components";
78

89
[Neon](https://neon.tech/) is a fully managed serverless PostgreSQL. It separates storage and compute to offer modern developer features, such as serverless, branching, and bottomless storage.
910

10-
## Set up an integration with Neon
11+
:::note
1112

12-
To set up an integration with Neon:
13+
You can connect to Neon using [Hyperdrive](/hyperdrive) (recommended), or using the Neon serverless driver, `@neondatabase/serverless`. Both provide connection pooling and reduce the amount of round trips required to create a secure connection from Workers to your database.
14+
15+
Hyperdrive can provide the lowest possible latencies because it performs the database connection setup and connection pooling across Cloudflare's network. Hyperdrive supports native database drivers, libraries, and ORMs, and is included in all [Workers plans](/hyperdrive/platform/pricing/). Learn more about Hyperdrive in [How Hyperdrive Works](/hyperdrive/configuration/how-hyperdrive-works/).
16+
17+
:::
18+
19+
<Tabs>
20+
<TabItem label="Hyperdrive (recommended)">
21+
22+
To connect to Neon using [Hyperdrive](/hyperdrive), follow these steps:
23+
24+
<Render file="neon-partial" product="hyperdrive"/>
25+
</TabItem>
26+
<TabItem label="Neon serverless driver">
27+
28+
To connect to Neon using `@neondatabase/serverless`, follow these steps:
1329

1430
1. You need to have an existing Neon database to connect to. [Create a Neon database](https://neon.tech/docs/postgres/tutorial-createdb#create-a-table) or [load data from an existing database to Neon](https://neon.tech/docs/import/import-from-postgres).
1531

@@ -58,18 +74,21 @@ To set up an integration with Neon:
5874
6. The following example shows how to make a query to your Neon database in a Worker. The credentials needed to connect to Neon have been added as secrets to your Worker.
5975

6076
```js
61-
import { Client } from '@neondatabase/serverless';
77+
import { Client } from "@neondatabase/serverless";
6278

6379
export default {
64-
async fetch(request, env, ctx) {
65-
const client = new Client(env.DATABASE_URL);
66-
await client.connect();
67-
const { rows } = await client.query('SELECT * FROM elements');
68-
ctx.waitUntil(client.end()); // this doesn’t hold up the response
69-
70-
return new Response(JSON.stringify(rows));
71-
}
72-
}
80+
async fetch(request, env, ctx) {
81+
const client = new Client(env.DATABASE_URL);
82+
await client.connect();
83+
const { rows } = await client.query("SELECT * FROM elements");
84+
ctx.waitUntil(client.end()); // this doesn’t hold up the response
85+
86+
return new Response(JSON.stringify(rows));
87+
},
88+
};
7389
```
7490

7591
To learn more about Neon, refer to [Neon's official documentation](https://neon.tech/docs/introduction).
92+
93+
</TabItem>
94+
</Tabs>

src/content/docs/workers/databases/third-party-integrations/planetscale.mdx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,27 @@ pcx_content_type: configuration
33
title: PlanetScale
44
---
55

6-
import { Render, PackageManagers } from "~/components";
6+
import { Render, PackageManagers, Tabs, TabItem } from "~/components";
77

88
[PlanetScale](https://planetscale.com/) is a MySQL-compatible platform that makes databases infinitely scalable, easier and safer to manage.
99

10+
:::note
11+
12+
You can connect to PlanetScale using [Hyperdrive](/hyperdrive) (recommended), or using the PlanetScale serverless driver, `@planetscale/database`. Both provide connection pooling and reduce the amount of round trips required to create a secure connection from Workers to your database.
13+
14+
Hyperdrive can provide lower latencies because it performs the database connection setup and connection pooling across Cloudflare's network. Hyperdrive supports native database drivers, libraries, and ORMs, and is included in all [Workers plans](/hyperdrive/platform/pricing/). Learn more about Hyperdrive in [How Hyperdrive Works](/hyperdrive/configuration/how-hyperdrive-works/).
15+
16+
:::
17+
18+
<Tabs>
19+
<TabItem label="Hyperdrive (recommended)">
20+
21+
To connect to PlanetScale using [Hyperdrive](/hyperdrive), follow these steps:
22+
23+
<Render file="planetscale-partial" product="hyperdrive"/>
24+
</TabItem>
25+
<TabItem label="PlanetScale serverless driver">
26+
1027
## Set up an integration with PlanetScale
1128

1229
To set up an integration with PlanetScale:
@@ -40,11 +57,11 @@ To set up an integration with PlanetScale:
4057
# Add the database host as a secret
4158
npx wrangler secret put DATABASE_HOST
4259
# When prompted, paste your PlanetScale host
43-
60+
4461
# Add the database username as a secret
4562
npx wrangler secret put DATABASE_USERNAME
4663
# When prompted, paste your PlanetScale username
47-
64+
4865
# Add the database password as a secret
4966
npx wrangler secret put DATABASE_PASSWORD
5067
# When prompted, paste your PlanetScale password
@@ -85,3 +102,6 @@ To set up an integration with PlanetScale:
85102
```
86103

87104
To learn more about PlanetScale, refer to [PlanetScale's official documentation](https://docs.planetscale.com/).
105+
106+
</TabItem>
107+
</Tabs>

src/content/docs/workers/databases/third-party-integrations/supabase.mdx

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,29 @@ pcx_content_type: configuration
33
title: Supabase
44
---
55

6-
import { Render, PackageManagers } from "~/components";
6+
import { Render, PackageManagers, Tabs, TabItem } from "~/components";
77

88
[Supabase](https://supabase.com/) is an open source Firebase alternative and a PostgreSQL database service that offers real-time functionality, database backups, and extensions. With Supabase, developers can quickly set up a PostgreSQL database and build applications.
99

10-
## Set up an integration with Supabase
10+
:::note
11+
12+
You can connect to Supabase using [Hyperdrive](/hyperdrive) (recommended), or using the Supabase client, `@supabase/supabase-js`. Both provide connection pooling and reduce the amount of round trips required to create a secure connection from Workers to your database.
13+
14+
Hyperdrive can provide lower latencies because it performs the database connection setup and connection pooling across Cloudflare's network. Hyperdrive supports native database drivers, libraries, and ORMs, and is included in all [Workers plans](/hyperdrive/platform/pricing/). Learn more about Hyperdrive in [How Hyperdrive Works](/hyperdrive/configuration/how-hyperdrive-works/).
15+
16+
:::
17+
18+
<Tabs>
19+
<TabItem label="Hyperdrive (recommended)">
20+
21+
When connecting to Supabase with Hyperdrive, you connect directly to the underlying Postgres database. This is [recommended by Supabase](https://supabase.com/docs/guides/database/connecting-to-postgres#choosing-a-connection-method) when accessed server-side from Workers.
22+
If you prefer to use the Supabase client, refer to the `Supabase client` tab. To connect to Supabase using [Hyperdrive](/hyperdrive), follow these steps:
23+
24+
<Render file="supabase-partial" product="hyperdrive"/>
25+
</TabItem>
26+
<TabItem label="Supabase client">
27+
28+
### Supabase client setup
1129

1230
To set up an integration with Supabase:
1331

@@ -41,7 +59,7 @@ To set up an integration with Supabase:
4159
# Add the Supabase URL as a secret
4260
npx wrangler secret put SUPABASE_URL
4361
# When prompted, paste your Supabase project URL
44-
62+
4563
# Add the Supabase anon key as a secret
4664
npx wrangler secret put SUPABASE_KEY
4765
# When prompted, paste your Supabase anon/public key
@@ -54,20 +72,23 @@ To set up an integration with Supabase:
5472
6. The following example shows how to make a query to your Supabase database in a Worker. The credentials needed to connect to Supabase have been added as secrets to your Worker.
5573

5674
```js
57-
import { createClient } from '@supabase/supabase-js';
75+
import { createClient } from "@supabase/supabase-js";
5876

5977
export default {
60-
async fetch(request, env) {
61-
const supabase = createClient(env.SUPABASE_URL, env.SUPABASE_KEY);
62-
const { data, error } = await supabase.from("countries").select('*');
63-
if (error) throw error;
64-
return new Response(JSON.stringify(data), {
65-
headers: {
66-
"Content-Type": "application/json",
67-
},
68-
});
69-
},
78+
async fetch(request, env) {
79+
const supabase = createClient(env.SUPABASE_URL, env.SUPABASE_KEY);
80+
const { data, error } = await supabase.from("countries").select("*");
81+
if (error) throw error;
82+
return new Response(JSON.stringify(data), {
83+
headers: {
84+
"Content-Type": "application/json",
85+
},
86+
});
87+
},
7088
};
7189
```
7290

7391
To learn more about Supabase, refer to [Supabase's official documentation](https://supabase.com/docs).
92+
93+
</TabItem>
94+
</Tabs>

src/content/docs/workers/databases/third-party-integrations/xata.mdx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,27 @@ pcx_content_type: configuration
33
title: Xata
44
---
55

6-
import { Render } from "~/components";
6+
import { Render, TabItem, Tabs } from "~/components";
77

88
[Xata](https://xata.io) is a serverless data platform powered by PostgreSQL. Xata uniquely combines multiple types of stores (relational databases, search engines, analytics engines) into a single service, accessible through a consistent REST API.
99

10+
:::note
11+
12+
You can connect to Xata using [Hyperdrive](/hyperdrive) (recommended), or using the Xata client, `@xata.io/client`. Both provide connection pooling and reduce the amount of round trips required to create a secure connection from Workers to your database.
13+
14+
Hyperdrive can provide lower latencies because it performs the database connection setup and connection pooling across Cloudflare's network. Hyperdrive supports native database drivers, libraries, and ORMs, and is included in all [Workers plans](/hyperdrive/platform/pricing/). Learn more about Hyperdrive in [How Hyperdrive Works](/hyperdrive/configuration/how-hyperdrive-works/).
15+
16+
:::
17+
18+
<Tabs>
19+
<TabItem label="Hyperdrive (recommended)">
20+
21+
To connect to Xata using [Hyperdrive](/hyperdrive), follow these steps:
22+
23+
<Render file="xata-partial" product="hyperdrive"/>
24+
</TabItem>
25+
<TabItem label="Supabase client">
26+
1027
## Set up an integration with Xata
1128

1229
To set up an integration with Xata:
@@ -23,11 +40,11 @@ To set up an integration with Xata:
2340
# Add the Xata API key as a secret
2441
npx wrangler secret put XATA_API_KEY
2542
# When prompted, paste your Xata API key
26-
43+
2744
# Add the Xata branch as a secret
2845
npx wrangler secret put XATA_BRANCH
2946
# When prompted, paste your Xata branch name (usually 'main')
30-
47+
3148
# Add the Xata database URL as a secret
3249
npx wrangler secret put XATA_DATABASE_URL
3350
# When prompted, paste your Xata database URL
@@ -82,3 +99,6 @@ To set up an integration with Xata:
8299
```
83100

84101
To learn more about Xata, refer to [Xata's official documentation](https://xata.io/docs).
102+
103+
</TabItem>
104+
</Tabs>

src/content/partials/hyperdrive/create-hyperdrive-config-mysql.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ id = "<ID OF THE CREATED HYPERDRIVE CONFIGURATION>"
5454

5555
## 3. Use Hyperdrive from your Worker
5656

57-
<Render file="use-mysql2-to-make-query" />
57+
<Render file="use-mysql2-to-make-query" product="hyperdrive" />

src/content/partials/hyperdrive/create-hyperdrive-config.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ id = "<ID OF THE CREATED HYPERDRIVE CONFIGURATION>"
5151

5252
## 3. Use Hyperdrive from your Worker
5353

54-
<Render file="use-postgres-js-to-make-query" />
54+
<Render file="use-node-postgres-to-make-query" product="hyperdrive" />

0 commit comments

Comments
 (0)