Primate LogoPrimate

MySQL

MySQL is a relational DBMS. Use it for durable, multi-connection workloads.

Setup

Install

npm install @primate/mysql

You need a running MySQL server. Create a database and user with access.

Configure

// config/db.ts
import mysql from "@primate/mysql";

export default mysql({
  database: "app",
  // host: "localhost",
  // port: 3306,
  // username: "root",
  // password: "secret",
  // pool: { max: 10, connectTimeout: 10_000, idleTimeout: 60_000 },
});

Options

option type default description
database string — Database name to use
host string "localhost" MySQL host
port number 3306 MySQL port
username string — Username (omit for socket auth)
password string — Password (omit if not required)
pool object driver defaults Connection pool controls

Pool controls use the shared max, connectTimeout, and idleTimeout options documented in Connection pools. Timeouts are milliseconds. max is an integer from 1 to 65,535. The timeout maximum is 2,147,483,647; connectTimeout starts at 1 and idleTimeout starts at 0. With mysql2, idleTimeout: 0 makes an idle connection eligible for the next cleanup pass. Omitted values preserve mysql2 defaults.

Use db.fork({ pool: { max: 2 } }) to create another pool that privately inherits the connection configuration. Close the fork when finished; its close() does not affect the parent pool.

Previous
MongoDB
Next
Oracle