Node MySQL 2
According to their official website (opens in a new tab),
mysql2
is a MySQL client for Node.js with focus on performance.
Drizzle ORM natively supports mysql2
with drizzle-orm/mysql2
package
npm i drizzle-orm mysql2
npm i -D drizzle-kit
There're two ways you can connect to the MySQL with mysql2
driver - it's either single client
connection or a pool
.
For the built in migrate
function with DDL migrations we and drivers strongly encourage you to use single client
connection.
For querying purposes feel free to use either client
or pool
based on your business demands.
index.ts
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";
const connection = await mysql.createConnection({
host: "host",
user: "user",
database: "database",
...
});
const db = drizzle(connection);