Registry / database / mysql-dialect-with-deadlock

mysql-dialect-with-deadlock

JSON →
library1.2.0jsnpmunverified

Custom MySQL dialect for Kysely (v1.2.0) that automatically retries queries on deadlock errors (MySQL error 1213). Drop-in replacement for Kysely's standard MySQL dialect with configurable retry attempts, exponential backoff, delay, and optional onRetry callback. Requires Kysely and mysql2 as peer dependencies. Ideal for production MySQL workloads where deadlocks are common.

npm install mysql-dialect-with-deadlock
INSTALL
IMPORT
SIG · MYSQL-DIALECT-WITH
M
mysql-dialect-with-deadlock
databasejavascriptv1.2.0
harness data pending
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());
Debug
Known issues
gotchaDeadlock retry only works with mysql2 package. Does not support mysql (mysqljs) package.
fix
Use mysql2 instead of mysql package.
affects: >=1.0.0
gotchaThe dialect is a drop-in replacement but requires Kysely version 0.24.0 or higher (ESM support).
fix
Ensure Kysely >=0.24.0 is installed (check package.json).
affects: >=1.0.0
deprecatedExponential backoff option 'backoff' may be deprecated in future versions; prefer 'shouldBackoff'? (unconfirmed).
fix
Use backoff: true for now; monitor releases for changes.
affects: 1.2.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module
Using CommonJS require() to import the ESM-only package.
fix
Replace require() with import or switch to ESM (e.g., type: 'module' in package.json).
Cannot find module 'kysely'
Missing peer dependency kyely.
fix
Run npm install kysely mysql2.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
kyselyrequiredpeer dependency - the dialect extends Kysely's query builder
mysql2requiredpeer dependency - provides MySQL client and pool
Agent activity
7 hits · last 30 days
node
6
Resources
mysql-dialect-with-deadlock — npm install mysql-dialect-with-deadlock · libregistry