UNPKG

@mikro-orm/postgresql

Version:

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.

52 lines (51 loc) 2.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PostgreSqlExceptionConverter = void 0; const core_1 = require("@mikro-orm/core"); class PostgreSqlExceptionConverter extends core_1.ExceptionConverter { /* istanbul ignore next */ /** * @link http://www.postgresql.org/docs/9.4/static/errcodes-appendix.html * @link https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractPostgreSQLDriver.php */ convertException(exception) { if (exception.detail?.toString().trim()) { exception.message += '\n - detail: ' + exception.detail; } if (exception.hint?.toString().trim()) { exception.message += '\n - hint: ' + exception.hint; } switch (exception.code) { case '40001': case '40P01': return new core_1.DeadlockException(exception); case '0A000': // Foreign key constraint violations during a TRUNCATE operation // are considered "feature not supported" in PostgreSQL. if (exception.message.includes('truncate')) { return new core_1.ForeignKeyConstraintViolationException(exception); } break; case '23502': return new core_1.NotNullConstraintViolationException(exception); case '23503': return new core_1.ForeignKeyConstraintViolationException(exception); case '23505': return new core_1.UniqueConstraintViolationException(exception); case '23514': return new core_1.CheckConstraintViolationException(exception); case '42601': return new core_1.SyntaxErrorException(exception); case '42702': return new core_1.NonUniqueFieldNameException(exception); case '42703': return new core_1.InvalidFieldNameException(exception); case '42P01': return new core_1.TableNotFoundException(exception); case '42P07': return new core_1.TableExistsException(exception); } return super.convertException(exception); } } exports.PostgreSqlExceptionConverter = PostgreSqlExceptionConverter;