ConnectMySQL
Source:
src/Railway/ConnectMySQL.ts
Bind a MySQL service to a Railway Service and obtain
the Effect-native connection string for Drizzle.MySQL /
SQL.MySQL.
ConnectMySQL is the Context tag, the type, and the callable —
yield* Railway.ConnectMySQL(Db). Provide ConnectMySQLHttp.
Examples
Section titled “Examples”import * as Drizzle from "alchemy/Drizzle/MySQL";
const conn = yield* Railway.ConnectMySQL(Db);const db = yield* Drizzle.MySQL(conn.connectionString);
fetch: Effect.gen(function* () { const rows = yield* db.execute("select 1 as ok", "objects");});Variable references
Section titled “Variable references”ConnectMySQL packs a typed private URI onto the Service. To store
Railway’s template instead of a resolved URI (IaC db.env.MYSQL_URL),
pass Railway.ref(Db, "MYSQL_URL") as a Variable value or
Service.env entry.
const db = yield* Railway.MySQL("Db", { project: site });yield* Railway.Variable("MysqlUrl", { project: site, service: api, name: "MYSQL_URL", value: Railway.ref(db, "MYSQL_URL"),});