Skip to content

Commit 7245e51

Browse files
committed
thomasgauvin: add new database examples to hyperdrive
1 parent 6e99f04 commit 7245e51

File tree

7 files changed

+82
-13
lines changed

7 files changed

+82
-13
lines changed

src/content/docs/hyperdrive/examples/aws-rds-aurora.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ summary: Connect Hyperdrive to an AWS RDS or Aurora database instance.
44
pcx_content_type: example
55
title: Connect to AWS RDS and Aurora
66
sidebar:
7-
order: 11
7+
order: 12
88
description: Connect Hyperdrive to an AWS RDS or Aurora database instance.
99
---
1010

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
type: example
3+
summary: Connect Hyperdrive to an Azure Database for PostgreSQL instance.
4+
pcx_content_type: example
5+
title: Connect to Azure Database
6+
sidebar:
7+
order: 10
8+
description: Connect Hyperdrive to a Azure Database for PostgreSQL instance.
9+
---
10+
11+
import { Render } from "~/components";
12+
13+
This example shows you how to connect Hyperdrive to an Azure Database for PostgreSQL instance.
14+
15+
## 1. Allow Hyperdrive access
16+
17+
To allow Hyperdrive to connect to your database, you will need to ensure that Hyperdrive has valid credentials and network access.
18+
19+
<Render file="public-connectivity" />
20+
21+
### Azure Portal
22+
23+
#### Public access networking
24+
25+
To connect to your Azure Database for PostgreSQL instance using public Internet connectivity:
26+
27+
1. In the [Azure Portal](https://portal.azure.com/), select the instance you want Hyperdrive to connect to.
28+
2. Expand **Settings** > **Networking** > ensure **Public access** is enabled > in **Firewall rules** add `0.0.0.0` as **Start IP address** and `255.255.255.255` as **End IP address**.
29+
3. Select **Save** to persist your changes.
30+
4. Select **Overview** from the sidebar and note down the **Server name** of your instance.
31+
32+
With the username, password, server name and database name (default: `postgres`), you can now create a Hyperdrive database configuration.
33+
34+
#### Private access networking
35+
36+
To connect to a private Azure Database for PostgreSQL instance, refer to [Connect to a private database using Tunnel](/hyperdrive/configuration/connect-to-private-database/).
37+
38+
## 2. Create a database configuration
39+
40+
<Render file="create-hyperdrive-config" />

src/content/docs/hyperdrive/examples/google-cloud-sql.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ summary: Connect Hyperdrive to a Google Cloud SQL database instance.
44
pcx_content_type: example
55
title: Connect to Google Cloud SQL
66
sidebar:
7-
order: 10
7+
order: 11
88
description: Connect Hyperdrive to a Google Cloud SQL database instance.
99
---
1010

src/content/docs/hyperdrive/examples/neon.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ title: Connect to Neon
66
sidebar:
77
order: 4
88
description: Connect Hyperdrive to a Neon Postgres database.
9-
109
---
1110

12-
import { Render } from "~/components"
11+
import { Render } from "~/components";
1312

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

src/content/docs/hyperdrive/examples/pgedge.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ title: Connect to pgEdge Cloud
66
sidebar:
77
order: 9
88
description: Connect Hyperdrive to a pgEdge Postgres database.
9-
109
---
1110

12-
import { Render } from "~/components"
11+
import { Render } from "~/components";
1312

14-
This example shows you how to connect Hyperdrive to a [pgEdge](https://pgedge.com/) Postgres database. pgEdge Cloud provides easy deployment of fully-managed, fully-distributed, and secure Postgres.
13+
This example shows you how to connect Hyperdrive to a [pgEdge](https://pgedge.com/) Postgres database. pgEdge Cloud provides easy deployment of fully-managed, fully-distributed, and secure Postgres.
1514

1615
## 1. Allow Hyperdrive access
1716

18-
You can connect Hyperdrive to any existing pgEdge database with the default user and password
17+
You can connect Hyperdrive to any existing pgEdge database with the default user and password
1918
provided by pgEdge.
2019

2120
### pgEdge dashboard
2221

22+
To retrieve your connection string from the pgEdge dashboard:
23+
2324
1. Go to the [**pgEdge dashboard**](https://app.pgedge.com) and select the database you wish to connect to.
2425
2. From the **Connect to your database** section, note down the connection string (starting with `postgres://app@...`) from the **Connection String** text box.
2526

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
type: example
3+
summary: Connect Hyperdrive to a Xata database instance.
4+
pcx_content_type: example
5+
title: Connect to Xata
6+
sidebar:
7+
order: 2
8+
description: Connect Hyperdrive to a Xata database instance.
9+
---
10+
11+
import { Render } from "~/components";
12+
13+
This example shows you how to connect Hyperdrive to a Xata PostgreSQL database instance.
14+
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" />

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ npm install postgres
5252
Copy the below Worker code, which passes the connection string generated from `env.HYPERDRIVE.connectionString` directly to the driver.
5353

5454
```ts
55-
import postgres from 'postgres'
55+
import postgres from "postgres";
5656

5757
export interface Env {
5858
// If you set another name in wrangler.toml as the value for 'binding',
@@ -62,20 +62,19 @@ export interface Env {
6262

6363
export default {
6464
async fetch(request, env, ctx): Promise<Response> {
65-
console.log(JSON.stringify(env));
6665
// Create a database client that connects to our database via Hyperdrive
6766
// Hyperdrive generates a unique connection string you can pass to
6867
// supported drivers, including node-postgres, Postgres.js, and the many
6968
// ORMs and query builders that use these drivers.
70-
const sql = postgres(env.HYPERDRIVE.connectionString)
69+
const sql = postgres(env.HYPERDRIVE.connectionString);
7170

7271
try {
7372
// Test query
74-
const result = await sql`SELECT * FROM pg_tables;`
73+
const result = await sql`SELECT * FROM pg_tables;`;
7574

7675
// Returns result rows as JSON
7776
return Response.json({ result: result });
78-
} catch (e) {
77+
} catch (e: any) {
7978
console.log(e);
8079
return Response.json({ error: e.message }, { status: 500 });
8180
}

0 commit comments

Comments
 (0)