UNPKG

sequelize-dm

Version:

Sequelize is a promise-based Node.js ORM tool for Postgres, MySQL, MariaDB, SQLite, Microsoft SQL Server, Amazon Redshift and Snowflake’s Data Cloud. It features solid transaction support, relations, eager and lazy loading, read replication and more.

44 lines (35 loc) 1.03 kB
import type { CommonErrorProperties, ErrorOptions } from './base-error'; import BaseError from './base-error'; export interface DatabaseErrorParent extends Error, Pick<CommonErrorProperties, 'sql'> { /** The parameters for the sql that triggered the error */ readonly parameters?: object; } export interface DatabaseErrorSubclassOptions extends ErrorOptions { parent?: DatabaseErrorParent; message?: string; } /** * A base class for all database related errors. */ class DatabaseError extends BaseError implements DatabaseErrorParent, CommonErrorProperties { parent: Error; original: Error; sql: string; parameters: object; constructor(parent: DatabaseErrorParent, options: ErrorOptions = {}) { super(parent.message); this.name = 'SequelizeDatabaseError'; this.parent = parent; this.original = parent; this.sql = parent.sql; this.parameters = parent.parameters ?? {}; if (options.stack) { this.stack = options.stack; } } } export default DatabaseError;