跳到主内容
@wquguru
精选78Cloudflare Hyperdrive(Changelog)云与平台

Cloudflare Hyperdrive MySQL 支持正式可用

Hyperdrive - MySQL support in Hyperdrive is now generally available

原文
发到 X
推荐理由

Cloudflare Workers 开发者注意:Hyperdrive 现已支持 MySQL,可直接连接任意 MySQL 数据库,无需改代码,定价与 Postgres 相同。若你正在用 Workers 访问 MySQL,现在可以接入 Hyperdrive 提升性能。

Support for MySQL in Hyperdrive is now generally available. You can connect to any MySQL database from your Workers using Hyperdrive.

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.

You can connect using your existing drivers, ORMs, and query builders with Hyperdrive's secure credentials, with no code changes required. MySQL support is available at the same pricing as Postgres.

代码 · 21
import { createConnection } from "mysql2/promise";
export default {
	async fetch(request, env, ctx) {
		const connection = await createConnection({
			host: env.HYPERDRIVE.host,
			user: env.HYPERDRIVE.user,
			password: env.HYPERDRIVE.password,
			database: env.HYPERDRIVE.database,
			port: env.HYPERDRIVE.port,
			disableEval: true, // Required for Workers compatibility
		});
		const [results, fields] = await connection.query("SHOW tables;");
		ctx.waitUntil(connection.end());
		return new Response(JSON.stringify({ results, fields }), {
			headers: {
				"Content-Type": "application/json",
				"Access-Control-Allow-Origin": "*",
			},
		});
	},
};
代码 · 24
import { createConnection } from "mysql2/promise";
export interface Env {
	HYPERDRIVE: Hyperdrive;
}
export default {
	async fetch(request, env, ctx): Promise<Response> {
		const connection = await createConnection({
			host: env.HYPERDRIVE.host,
			user: env.HYPERDRIVE.user,
			password: env.HYPERDRIVE.password,
			database: env.HYPERDRIVE.database,
			port: env.HYPERDRIVE.port,
			disableEval: true, // Required for Workers compatibility
		});
		const [results, fields] = await connection.query("SHOW tables;");
		ctx.waitUntil(connection.end());
		return new Response(JSON.stringify({ results, fields }), {
			headers: {
				"Content-Type": "application/json",
				"Access-Control-Allow-Origin": "*",
			},
		});
	},
} satisfies ExportedHandler<Env>;

Learn more about how Hyperdrive works and get started building Workers that connect to MySQL with Hyperdrive.

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

另一事件,读法相近