Registry /
database / mysql-dialect-with-deadlock
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
MySQLDialectWithDeadlockRetries
✓ import { MySQLDialectWithDeadlockRetries } from 'mysql-dialect-with-deadlock'
✗ const MySQLDialectWithDeadlockRetries = require('mysql-dialect-with-deadlock')
Package is ESM-only (exports default class, but requires named import). CommonJS require will not work.
Kysely
✓ import { Kysely } from 'kysely'
✗ const Kysely = require('kysely').Kysely
Kysely is an ESM-only package; must use named import.
createPool
✓ import { createPool } from 'mysql2'
✗ import mysql from 'mysql2'; const pool = mysql.createPool(...)
Direct named import is idiomatic; default import also works but named import is preferred.
Creates a Kysely instance with MySQLDialectWithDeadlockRetries, connects to MySQL using env vars, and runs a simple select query with automatic deadlock retry configuration.
import { Kysely } from 'kysely';
import { createPool } from 'mysql2';
import { MySQLDialectWithDeadlockRetries } from 'mysql-dialect-with-deadlock';
const db = new Kysely({
dialect: new MySQLDialectWithDeadlockRetries({
pool: createPool({
host: process.env.DB_HOST ?? 'localhost',
user: process.env.DB_USER ?? 'root',
database: process.env.DB_NAME ?? 'test',
password: process.env.DB_PASSWORD ?? ''
}),
deadlock: {
maxAttempts: 5,
delay: 100,
backoff: true,
onRetry: (error, attempt) => {
console.log(`Deadlock retry #${attempt}: ${error.message}`);
}
}
})
});
async function main() {
const result = await db.selectFrom('users').selectAll().execute();
console.log(result);
}
main().catch(console.error).finally(() => db.destroy());
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module
Using CommonJS require() to import the ESM-only package.
fixReplace require() with import or switch to ESM (e.g., type: 'module' in package.json).
Cannot find module 'kysely'
Missing peer dependency kyely.
fixRun npm install kysely mysql2.
Audit
Dependencies
kyselyrequiredpeer dependency - the dialect extends Kysely's query builder
mysql2requiredpeer dependency - provides MySQL client and pool