Skip to main content

Error Handling and Debugging

By default, MySQL2 ORM is designed to avoid using the try-catch block in its methods, but it's possible to enable error throwing or debug them in cosole.

This page doesn't apply to the execute and query methods exposed, nor to the adapted beginTransaction, commit, rollback and release methods, which remain as they are in the original MySQL2.

Enable Error Throwing

import { MySQL } from 'mysql2-orm';

const pool = new MySQL({
// ...
});

pool.enableThrow();

Disable Error Throwing

import { MySQL } from 'mysql2-orm';

const pool = new MySQL({
// ...
});

pool.disableThrow();

Enable Error Debug

import { MySQL } from 'mysql2-orm';

const pool = new MySQL({
// ...
});

pool.enableDebug();

Disable Error Debug

import { MySQL } from 'mysql2-orm';

const pool = new MySQL({
// ...
});

pool.disableDebug();

Enable Query Debug (verbose)

Be careful, showing queries in the console can expose sensitive data.

import { MySQL } from 'mysql2-orm';

const pool = new MySQL({
// ...
});

pool.enableVerbose();

Disable Query Debug (verbose)

import { MySQL } from 'mysql2-orm';

const pool = new MySQL({
// ...
});

pool.disableVerbose();