MySQL
@mountsqli/driver-mysql wraps mysql2. It uses ? parameter style (pass-through)
and surfaces AUTO_INCREMENT insert IDs.
Install & use
Section titled “Install & use”pnpm add @mountsqli/driver-mysql mysql2import "@mountsqli/driver-mysql";import { mountsqli } from "@mountsqli/core";
const db = mountsqli({ driver: "mysql", url: process.env.DATABASE_URL!, tables: [users],});Parameter style
Section titled “Parameter style”The dialect compiles plans to ? placeholders:
SELECT * FROM `users` WHERE `age` > ?Insert IDs
Section titled “Insert IDs”MySQL uses AUTO_INCREMENT. The driver returns the generated id via insertId
on insert, surfaced through returning("id"):
const { rows } = await db.from(users).returning("id").insert({ email: "a@b.c" });// rows[0].id is the AUTO_INCREMENT valueBest for
Section titled “Best for”- Existing MySQL infrastructures.
- Apps already standardized on
mysql2.
Best practices
Section titled “Best practices”- Load
DATABASE_URLfrom env. - Use
returning("id")to read the generated key. - Prefer this driver when your org mandates MySQL.
Common mistakes
Section titled “Common mistakes”- Assuming
$Nparams (MySQL uses?). - Forgetting
mysql2is a peer dependency.
Related
Section titled “Related”- Drivers → Overview — driver model.
- Insert —
returning()for IDs.
