Skip to content

Commit c894a44

Browse files
committed
fix snippet issue
1 parent b2ac3a5 commit c894a44

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,36 @@ Hyperdrive makes your regional, MySQL databases fast when connecting from Cloudf
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-
import mysqlRaw from "~/content/partials/hyperdrive/mysql-snippet-slim.mdx?raw";
17+
```ts
18+
import { createConnection } from "mysql2/promise";
1819

19-
<Code code={mysqlRaw} lang="typescript" />
20+
export interface Env {
21+
HYPERDRIVE: Hyperdrive;
22+
}
23+
24+
export default {
25+
async fetch(request, env, ctx): Promise<Response> {
26+
const connection = await createConnection({
27+
host: env.HYPERDRIVE.host,
28+
user: env.HYPERDRIVE.user,
29+
password: env.HYPERDRIVE.password,
30+
database: env.HYPERDRIVE.database,
31+
port: env.HYPERDRIVE.port,
32+
disableEval: true, // Required for Workers compatibility
33+
});
34+
35+
const [results, fields] = await connection.query("SHOW tables;");
36+
37+
ctx.waitUntil(connection.end());
38+
39+
return new Response(JSON.stringify({ results, fields }), {
40+
headers: {
41+
"Content-Type": "application/json",
42+
"Access-Control-Allow-Origin": "*",
43+
},
44+
});
45+
},
46+
} satisfies ExportedHandler<Env>;
47+
```
2048

2149
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/).

src/content/partials/hyperdrive/mysql-snippet-slim.mdx

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)