1.0.3 • Published 2 years ago
pg-constants v1.0.3
pg-constants
Library with mapping of codes and messages to identify PostgreSQL errors.
Example
Catch an error when trying to create a row in a database that conflicts with another.
import { PgErrors } from 'pg-constants';
try {
await user.save();
} catch (e) {
if (e.code === PgErrors.UNIQUE_VIOLATION) {
throw new Error('User with such email already exists');
}
throw e;
}