Skip to content

Commit b2ac3a5

Browse files
committed
adjust per pr comments
1 parent 97c7fba commit b2ac3a5

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/content/changelog/hyperdrive/2025-04-08-hyperdrive-mysql-support.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ products:
66
date: 2025-04-08T14:00:00Z
77
---
88

9-
![Hyperdrive query latency decreases by 90% during Hyperdrive's gradual rollout of regional pooling.](~/assets/images/hyperdrive/configuration/hyperdrive-hero.png)
9+
import { Code } from "~/components";
1010

11-
Hyperdrive now supports connecting to MySQL and MySQL-compatible databases, including Amazon RDS and Aurora MySQL, Google Cloud SQL for MySQL, Azure Database for MySQL, PlanetScale, and MariaDB.
11+
Hyperdrive now supports connecting to MySQL and MySQL-compatible databases, including Amazon RDS MySQL, Google Cloud SQL for MySQL, Azure Database for MySQL, and PlanetScale.
1212

1313
Hyperdrive makes your regional, MySQL databases fast when connecting from Cloudflare Workers. It eliminates unnecessary network roundtrips during connection setup, pools database connections globally, and can cache query results to provide the fastest possible response times.
1414

1515
Best of all, you can connect using your existing drivers, ORMs, and query builders with Hyperdrive's secure credentials, no code changes required.
1616

17-
Learn more about [how Hyperdrive works](/hyperdrive/configuration/how-hyperdrive-works/) and [get started with Hyperdrive for MySQL](/hyperdrive/get-started/).
17+
import mysqlRaw from "~/content/partials/hyperdrive/mysql-snippet-slim.mdx?raw";
18+
19+
<Code code={mysqlRaw} lang="typescript" />
20+
21+
Learn more about [how Hyperdrive works](/hyperdrive/configuration/how-hyperdrive-works/) and [get started building Workers that connect to MySQL with Hyperdrive](/hyperdrive/get-started/).
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { createConnection } from "mysql2/promise";
2+
3+
export interface Env {
4+
HYPERDRIVE: Hyperdrive;
5+
}
6+
7+
export default {
8+
async fetch(request, env, ctx): Promise<Response> {
9+
const connection = await createConnection({
10+
host: env.HYPERDRIVE.host,
11+
user: env.HYPERDRIVE.user,
12+
password: env.HYPERDRIVE.password,
13+
database: env.HYPERDRIVE.database,
14+
port: env.HYPERDRIVE.port,
15+
disableEval: true, // Required for Workers compatibility
16+
});
17+
18+
const [results, fields] = await connection.query("SHOW tables;");
19+
20+
ctx.waitUntil(connection.end());
21+
22+
return new Response(JSON.stringify({ results, fields }), {
23+
headers: {
24+
"Content-Type": "application/json",
25+
"Access-Control-Allow-Origin": "*",
26+
},
27+
});
28+
29+
}} satisfies ExportedHandler<Env>;

0 commit comments

Comments
 (0)