VibORM

MySQL2

MySQL driver using mysql2 with connection pooling

Installation

pnpm add mysql2

Configuration

import { createClient } from "viborm/drivers/mysql2";

const client = createClient({
  databaseUrl: "mysql://user:password@localhost:3306/database",
  schema,
});

Options

OptionTypeDescription
poolPoolExisting mysql2 pool instance
optionsPoolOptionsmysql2 pool configuration
databaseUrlstringMySQL connection URL

Using Pool Options

import { createClient } from "viborm/drivers/mysql2";

const client = createClient({
  options: {
    host: "localhost",
    port: 3306,
    user: "root",
    password: "password",
    database: "mydb",
    connectionLimit: 10,
  },
  schema,
});

Using Existing Pool

import { createPool } from "mysql2/promise";
import { createClient } from "viborm/drivers/mysql2";

const pool = createPool({
  host: "localhost",
  user: "root",
  database: "mydb",
});

const client = createClient({
  pool,
  schema,
});

Transactions

MySQL2 supports full transactions with savepoints for nested transactions.

await client.$transaction(async (tx) => {
  await tx.user.create({ data: { name: "Alice" } });
  await tx.post.create({ data: { title: "Hello", authorId: "..." } });
});

Limitations

  • No RETURNING clause - VibORM uses LAST_INSERT_ID() for inserts
  • JSON columns return as strings and are parsed automatically
  • Boolean values stored as TINYINT(1)

On this page