{"id":"595207b949780546","repo":"drizzle-team/drizzle-orm","slug":"transactions-are-not-supported-by-the-mysql-proxy","errorCode":null,"errorMessage":"Transactions are not supported by the MySql Proxy driver","messagePattern":"Transactions are not supported by the MySql Proxy driver","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/mysql-proxy/session.ts","lineNumber":89,"sourceCode":"\t\t\tcacheConfig,\n\t\t\tfields,\n\t\t\tcustomResultMapper,\n\t\t\tgeneratedIds,\n\t\t\treturningIds,\n\t\t) as PreparedQueryKind<MySqlRemotePreparedQueryHKT, T>;\n\t}\n\n\toverride all<T = unknown>(query: SQL): Promise<T[]> {\n\t\tconst querySql = this.dialect.sqlToQuery(query);\n\t\tthis.logger.logQuery(querySql.sql, querySql.params);\n\t\treturn this.client(querySql.sql, querySql.params, 'all').then(({ rows }) => rows) as Promise<T[]>;\n\t}\n\n\toverride async transaction<T>(\n\t\t_transaction: (tx: MySqlProxyTransaction<TFullSchema, TSchema>) => Promise<T>,\n\t\t_config?: MySqlTransactionConfig,\n\t): Promise<T> {\n\t\tthrow new Error('Transactions are not supported by the MySql Proxy driver');\n\t}\n}\n\nexport class MySqlProxyTransaction<\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n> extends MySqlTransaction<MySqlRemoteQueryResultHKT, MySqlRemotePreparedQueryHKT, TFullSchema, TSchema> {\n\tstatic override readonly [entityKind]: string = 'MySqlProxyTransaction';\n\n\toverride async transaction<T>(\n\t\t_transaction: (tx: MySqlProxyTransaction<TFullSchema, TSchema>) => Promise<T>,\n\t): Promise<T> {\n\t\tthrow new Error('Transactions are not supported by the MySql Proxy driver');\n\t}\n}\n\nexport class PreparedQuery<T extends MySqlPreparedQueryConfig> extends PreparedQueryBase<T> {\n\tstatic override readonly [entityKind]: string = 'MySqlProxyPreparedQuery';","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/mysql-proxy/session.ts#L71-L107","documentation":"A plain Error 'Transactions are not supported by the MySql Proxy driver' thrown by MySqlRemoteSession.transaction() (drizzle-orm/src/mysql-proxy/session.ts:89). The mysql-proxy adapter (drizzle-orm/mysql-proxy) talks to a remote callback over the wire and intentionally has no transaction implementation — calling db.transaction() always throws synchronously.","triggerScenarios":"Constructing the DB with drizzle-orm/mysql-proxy's drizzle(remoteCallback, { schema }) and then calling db.transaction(async tx => { ... }) (with or without a config argument). The override throws immediately.","commonSituations":"Migrating from mysql2/node-mysql2 to the proxy driver for an edge/serverless HTTP setup and leaving existing db.transaction() call sites in place. The proxy is meant for stateless request/response, so multi-statement transactions are impossible.","solutions":["Switch to a driver that supports transactions: drizzle-orm/mysql2 with a real Pool for serverful apps.","If you must stay on the proxy, restructure logic to avoid transactions (single statements, or server-side transaction endpoints invoked via the remote callback).","Remove or guard all db.transaction() call sites when adopting mysql-proxy."],"exampleFix":"// before\nimport { drizzle } from 'drizzle-orm/mysql-proxy';\nconst db = drizzle(remoteCallback, { schema });\nawait db.transaction(async (tx) => { /* ... */ }); // throws\n\n// after — use mysql2 driver which supports transactions\nimport mysql from 'mysql2/promise';\nimport { drizzle } from 'drizzle-orm/mysql2';\nconst db = drizzle(mysql.createPool(process.env.DATABASE_URL!), { schema, mode: 'default' });\nawait db.transaction(async (tx) => { /* ... */ });","handlingStrategy":"validation","validationCode":"import { MySqlRemoteSession } from 'drizzle-orm/mysql-proxy';\nimport type { MySqlDatabase } from 'drizzle-orm/mysql-core';\n\nfunction supportsTransactions(db: MySqlDatabase<any, any, any, any>): boolean {\n  // mysql-proxy uses MySqlRemoteSession whose transaction() throws\n  return !(db.session instanceof MySqlRemoteSession);\n}\n\nif (!supportsTransactions(db)) {\n  throw new Error('This code path requires a transaction-capable MySQL driver (use mysql2).');\n}","typeGuard":"import { MySqlRemoteSession } from 'drizzle-orm/mysql-proxy';\n\nfunction isProxySession(db: any): boolean {\n  return db?.session instanceof MySqlRemoteSession;\n}","tryCatchPattern":"try {\n  await db.transaction(async (tx) => { /* ... */ });\n} catch (e) {\n  if (e instanceof Error && /not supported by the MySql Proxy driver/i.test(e.message)) {\n    // switch to a transaction-capable driver instead of retrying\n    throw new Error('Transactions unavailable on mysql-proxy; use drizzle-orm/mysql2.');\n  }\n  throw e;\n}","preventionTips":["Before adopting mysql-proxy, grep for db.transaction( and remove/guard every call site.","Prefer mysql2 for any flow that needs atomicity.","Document in the repo that mysql-proxy is transaction-free."],"tags":["mysql","mysql-proxy","transaction","unsupported"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}