MysqlStateProvider
TypeExperimentalSignature
type MysqlStateProvider<TTxContext> = {
classifyError: (options) => MysqlErrorClassification | undefined;
close?: () => Promise<void>;
executeSql: (options) => Promise<unknown[]>;
isTransaction: (txCtx) => boolean;
onTransactionCommit: (txCtx, callback) => void;
onTransactionRollback: (txCtx, callback) => void;
withTransaction: <T>(fn) => Promise<T>;
};mysql/src/state-provider/state-provider.mysql.ts:29
MySQL and MariaDB state provider interface.
Abstracts database client operations, providing context management, transaction handling,
and SQL execution. Users create their own implementation to integrate with their preferred
client (mysql2, mariadb, Drizzle, Kysely, etc.).
Every connection must have a default database selected, even when the adapter's schema names
another one: MySQL rejects multi-table updates over JSON_TABLE on a connection without one.
Type Parameters
- TTxContextextends
BaseTxContextThe transaction context type containing database client/connection info
Properties
classifyError
Signature
classifyError: (options) => MysqlErrorClassification | undefined;mysql/src/state-provider/state-provider.mysql.ts:71
Classifies an error thrown by this provider's driver. Returns undefined for any other.
Parameters
- options
object - options.error
unknown
Returns
MysqlErrorClassification |undefined
close?
Signature
close?: () => Promise<void>;mysql/src/state-provider/state-provider.mysql.ts:77
Releases provider-owned resources. Optional — providers that wrap a caller-owned client or pool can omit it. When defined, must be idempotent.
Returns
Promise<void>
executeSql
Signature
executeSql: (options) => Promise<unknown[]>;mysql/src/state-provider/state-provider.mysql.ts:60
Executes one SQL statement with ? placeholders and returns its rows, or an empty array for a
statement that returns none. When txCtx is omitted, runs on a connection of its own.
id marks a statement worth preparing server-side; without it the provider may use the text
protocol. Providers must not enable multiple statements per call.
Parameters
- options
object - options.columnTypes
Record<string,RuntimeType> - options.id?
string - options.params
unknown[] - options.paramTypes
Record<number,RuntimeType> - options.readOnly
boolean - options.sql
string - options.txCtx?
TTxContext
Returns
Promise<unknown[]>
isTransaction
Signature
isTransaction: (txCtx) => boolean;mysql/src/state-provider/state-provider.mysql.ts:42
Whether txCtx is inside an open transaction. Must be synchronous and must not query the
database.
Parameters
- txCtx
TTxContext
Returns
boolean
onTransactionCommit
Signature
onTransactionCommit: (txCtx, callback) => void;mysql/src/state-provider/state-provider.mysql.ts:45
Runs callback after txCtx's transaction commits, before the call that opened it settles.
Parameters
- txCtx
TTxContext - callback(
) => void|Promise<void>
Returns
void
onTransactionRollback
Signature
onTransactionRollback: (txCtx, callback) => void;mysql/src/state-provider/state-provider.mysql.ts:51
Runs callback synchronously when txCtx's transaction, or the savepoint txCtx belongs to,
rolls back. Commit callbacks registered there never run.
Parameters
- txCtx
TTxContext - callback(
) => void
Returns
void
withTransaction
Signature
withTransaction: <T>(fn) => Promise<T>;mysql/src/state-provider/state-provider.mysql.ts:36
Executes a callback within a database transaction at READ COMMITTED: issues
SET TRANSACTION ISOLATION LEVEL READ COMMITTED and then START TRANSACTION on the same
connection with nothing between them, commits on success, rolls back on error, and releases
the connection.
Type Parameters
- T
Parameters
- fn(
txCtx) =>Promise<T>
Returns
Promise<T>