Skip to content

postgrelize / ConstraintErrorOptions

Type Alias: ConstraintErrorOptions ​

ConstraintErrorOptions = QueryErrorContext & Readonly<{ constraint?: string; fields?: Readonly<Record<string, string>> | readonly string[]; message?: string; parent?: DriverError; table?: string; }>

Defined in: src/errors/database-errors.ts:142

Input of the constraint error constructors: the driver error plus what PostgreSQL reported about the constraint.

Example ​

ts
const options: ConstraintErrorOptions = {
  parent: Object.assign(new Error('violates foreign key constraint'), { code: '23503' }),
  fields: ['userId'],
  table: 'posts',
  constraint: 'posts_userId_fkey',
  sql: 'INSERT INTO "posts" ("userId") VALUES ($1)',
  parameters: [42],
};
const error = new ForeignKeyConstraintError(options);

Released under the MIT License.