SQL.MySQL reference
Source:
packages/sql/src/MySQL.ts
Open an @effect/sql-mysql2 client (a connection pool) from a connection
URL — a plain Redacted or an Effect of one, e.g. Hyperdrive’s
connectionString:
import * as SQL from "@alchemy.run/sql/MySQL";
const hd = yield* Cloudflare.Hyperdrive.Connect(Hyperdrive);const sql = yield* SQL.MySQL({ url: hd.connectionString });
fetch: Effect.gen(function* () { const users = yield* sql`SELECT * FROM users`;});The client is a real MysqlClient: sql`...`, sql.insert and
sql.and build and compile statements with @effect/sql-mysql2’s own
code, with no connection. Running a statement opens the pool. The pool is
opened at most once per execution and closes when the event settles. The
connection URL resolves then too, so deploy / plan-time invocations never
connect. Workers defaults (resolveMySQLConfig) are overridden in
the config:
const sql = yield* SQL.MySQL({ url, disablePreparedStatements: true, poolConfig: { ssl: { rejectUnauthorized: true } },});