Skip to content

MySQL

@mountsqli/driver-mysql wraps mysql2. It uses ? parameter style (pass-through) and surfaces AUTO_INCREMENT insert IDs.

Terminal window
pnpm add @mountsqli/driver-mysql mysql2
import "@mountsqli/driver-mysql";
import { mountsqli } from "@mountsqli/core";
const db = mountsqli({
driver: "mysql",
url: process.env.DATABASE_URL!,
tables: [users],
});

The dialect compiles plans to ? placeholders:

SELECT * FROM `users` WHERE `age` > ?

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 value
  • Existing MySQL infrastructures.
  • Apps already standardized on mysql2.
  • Load DATABASE_URL from env.
  • Use returning("id") to read the generated key.
  • Prefer this driver when your org mandates MySQL.
  • Assuming $N params (MySQL uses ?).
  • Forgetting mysql2 is a peer dependency.