Skip to content

Drizzle.MySQL reference

Source: packages/drizzle/src/MySQL.ts

Open a Drizzle/MySQL database from a connection URL using the drizzle-orm/effect-mysql2 integration.

const conn = yield* Cloudflare.Hyperdrive.Connect(Hyperdrive);
const db = yield* Drizzle.MySQL(conn.connectionString, { relations });
fetch: Effect.gen(function* () {
const rows = yield* db.select().from(users);
});

The database is a real EffectMysql2Database. Queries, subqueries, CTEs and sql fragments are built by drizzle’s own code, with no connection. Running a query opens the pool. The pool is opened at most once per execution and closes when the event settles. The connection string resolves then too, so deploy / plan-time invocations never connect. Workers defaults (resolveMySQLConfig) are overridden via config.client:

const db = yield* Drizzle.MySQL(connectionString, {
relations,
client: { poolConfig: { ssl: { rejectUnauthorized: true } } },
});