import type { DatabaseConnection } from '../../driver/database-connection.js'; import type { AbortableOperationOptions } from '../../util/abort.js'; /** * Config for the MySQL dialect. */ export interface MysqlDialectConfig { /** * A `mysql2` `Client` constructor, to be used for connecting to the database * outside of the `pool` to avoid waiting for an idle connection. * * This is useful for cancelling queries on the database side. */ controlConnection?: (config: object) => MysqlConnection; /** * A mysql2 Pool instance or a function that returns one. * * If a function is provided, it's called once when the first query is executed. * * https://github.com/sidorares/node-mysql2#using-connection-pools */ pool: MysqlPool | ((options?: AbortableOperationOptions) => Promise); /** * Called once for each created connection. */ onCreateConnection?: (connection: DatabaseConnection, options?: AbortableOperationOptions) => Promise; /** * Called every time a connection is acquired from the pool. */ onReserveConnection?: (connection: DatabaseConnection, options?: AbortableOperationOptions) => Promise; } /** * This interface is the subset of mysql2 driver's `Pool` class that * kysely needs. * * We don't use the type from `mysql2` here to not have a dependency to it. * * https://github.com/sidorares/node-mysql2#using-connection-pools */ export interface MysqlPool { getConnection(callback: (error: unknown, connection: MysqlPoolConnection) => void): void; end(callback: (error: unknown) => void): void; } export interface MysqlConnection { config: object; connect(callback?: (error: unknown) => void): void; destroy(): void; query(sql: string, parameters: Array): { stream: (options: MysqlStreamOptions) => MysqlStream; }; query(sql: string, parameters: Array, callback: (error: unknown, result: MysqlQueryResult) => void): void; threadId: number; } export type MysqlConectionConstructor = new (opts?: object) => MysqlConnection; export interface MysqlPoolConnection extends MysqlConnection { release(): void; } export interface MysqlStreamOptions { highWaterMark?: number; objectMode?: true; } export interface MysqlStream { [Symbol.asyncIterator](): AsyncIterableIterator; } export interface MysqlOkPacket { affectedRows: number; changedRows: number; insertId: number; } export type MysqlQueryResult = MysqlOkPacket | Record[];