import { on as MigrationAdapter } from "./index-DcuMZ9kb.mjs"; import { Dialect } from "kysely"; //#region src/adapters/mysql/adapter.d.ts /** * mysql2-shaped pool that `mysqlAdapter` consumes. Mirrors the * structural surface of `mysql2/promise`'s Pool. The adapter only * uses `query(...)` and `getConnection(...)` so any mysql2-compatible * driver works. * * Return type is `Promise<[R, unknown]>` (not `[R[], unknown]`) so * mysql2's `Pool.query()` is structurally assignable: SELECT * statements return `RowDataPacket[]` (so callers pass `R = * MyRow[]`), INSERT / UPDATE / DELETE return `ResultSetHeader` (so * callers pass `R = ResultSetHeader`). Each adapter call site picks * the row shape it expects via the type parameter. */ interface MysqlConnectionLike { query(sql: string, params?: readonly unknown[]): Promise<[R, unknown]>; release(): void; } interface MysqlPoolLike { query(sql: string, params?: readonly unknown[]): Promise<[R, unknown]>; getConnection(): Promise; } interface MysqlAdapterOptions { /** * mysql2-compatible Pool. Caller-owned — `close()` on the adapter * does NOT end the pool because adopters typically share a single * pool across the migration adapter and the KickDbClient. */ pool: MysqlPoolLike; } /** * Parsed shape returned by `parseMysqlVersion`. `flavor` lets * adopters distinguish MySQL from MariaDB without re-grepping the * raw string. */ interface ParsedMysqlVersion { flavor: 'mysql' | 'mariadb'; major: number; minor: number; } /** * Parse a MySQL `SELECT VERSION()` string. Handles: * * - MySQL: `8.0.34`, `8.4.0`, `5.7.42-log` * - MariaDB plain: `10.6.11-MariaDB`, `10.5.21-MariaDB-log`, * `10.4.32-MariaDB` * - MariaDB w/ compat prefix: `5.5.5-10.6.11-MariaDB-1:10.6.11+maria~ubu2004` * (the leading `5.5.5-` is a wire-protocol thing for older MySQL * clients; the real server version sits immediately before * `-MariaDB`) * * Returns `null` on unparseable input. */ declare function parseMysqlVersion(version: string): ParsedMysqlVersion | null; /** * Back-compat shim — pre-existing API surface that returned the * major version only. Kept exported so adopters depending on it * keep working; new code should use `parseMysqlVersion`. * * @deprecated Use `parseMysqlVersion` for full version + flavor info. */ declare function parseMysqlMajorVersion(version: string): number | null; /** * Split a SQL blob into individual statements at the top-level `;` * boundary. Respects single-quote / double-quote / backtick string * literals AND `--` line comments + C-style block comments — * `;` inside any of those does not terminate a statement. * * mysql2's default `Pool.query()` rejects multi-statement SQL unless * the driver was created with `multipleStatements: true`. Splitting * lets the adapter run kickjs-emitted DDL (multi-statement, but * always semicolon-separated at the top level) without that flag. * * Two MySQL-specific quirks the splitter handles: * * - **`--` comments require trailing whitespace/end-of-input.** * Per MySQL docs, `--` is only a line-comment introducer when * followed by whitespace (space/tab/newline) or end-of-input — * otherwise it's two unary-minus operators (`5--3` evaluates * to `8`). Bare `--xyz` is a parse error in MySQL but kickjs * should pass it through unchanged so the driver surfaces the * real error, not silently swallow the rest of the line. * - **Doubled-quote string escapes.** MySQL accepts both * backslash-escapes (`'it\'s'`) and SQL-standard doubled-quote * escapes (`'it''s'`). The state machine peeks for the doubled * form and stays in-string. Same rule applies to `""` inside * double-quoted strings. * * Adopter-written migrations with pathological SQL — e.g. `;` in * an unterminated block comment — won't split correctly. * Documented in the README; turn on `multipleStatements: true` on * the pool if you hit it. */ declare function splitMysqlStatements(sql: string): string[]; /** * MigrationAdapter implementation backed by mysql2. * * Asserts MySQL 8.0+ (or MariaDB 10.5+) on first connection (via * the first `ensureMigrationTables` call, lazily — no I/O at * construction time). Earlier versions throw `KickDbError` with * code `KICK_DB_RELATIONAL_NOT_SUPPORTED` carrying the detected * version so adopters get a clear error before any query reaches * the relational compiler. * * Multi-statement support: every `query()` call splits the SQL * blob at top-level semicolons and runs each statement * sequentially. Works against mysql2's default settings; adopters * who set `multipleStatements: true` on the pool pay no extra * cost (the split is cheap on small DDL blobs). * * Lock semantics: single-row UPDATE WHERE locked_at IS NULL on * `kick_migrations_lock`. Only the row created by * `ensureMigrationTables()` exists, so the UPDATE either flips * `locked_at` and returns `affectedRows=1` (we won) or matches * zero rows (someone else holds it). * * Introspection: not implemented in v1 — throws `KickDbError` with * code `KICK_DB_INTROSPECT_NOT_SUPPORTED`. Drift detection lands * in a follow-up that walks `information_schema`. */ declare function mysqlAdapter(opts: MysqlAdapterOptions): MigrationAdapter; //#endregion //#region src/adapters/mysql/dialect.d.ts interface MysqlDialectOptions { /** * mysql2-compatible pool. Both `mysql.createPool(...)` from * `mysql2/promise` and `mysql2.createPool(...)` (callback API * wrapped in a promise) match structurally. */ pool: MysqlPoolLike; } /** * Construct the dialect that `createDbClient({ dialect })` consumes. * * **MySQL 8.0+ required.** Kickjs-db's relational query layer * compiles to `JSON_ARRAYAGG`, which shipped in 8.0. Adapter-side * version assertion lands at first connection from `mysqlAdapter()`; * see that factory's docs. * * @example * ```ts * import { createDbClient } from '@forinda/kickjs-db' * import { mysqlAdapter, mysqlDialect } from '@forinda/kickjs-db/mysql' * import { createPool } from 'mysql2/promise' * * const pool = createPool({ * host: '127.0.0.1', user: 'root', password: '...', database: 'app', * }) * * export const db = createDbClient({ * schema, * dialect: mysqlDialect({ pool }), * }) * * export const migrationAdapter = mysqlAdapter({ pool }) * ``` */ declare function mysqlDialect(opts: MysqlDialectOptions): Dialect; //#endregion export { MysqlAdapterOptions, MysqlConnectionLike, MysqlDialectOptions, MysqlPoolLike, ParsedMysqlVersion, mysqlAdapter, mysqlDialect, parseMysqlMajorVersion, parseMysqlVersion, splitMysqlStatements }; //# sourceMappingURL=mysql.d.mts.map