1.1.0 • Published 1 year ago
@hibanka/pg-utils v1.1.0
@hibanka/pg-utils
Node.js utility library for PostgreSQL database
Installation
npm install @hibanka/pg-utils
Usage
Error Identification
This allows you to programmatically catch database errors.
import { PgErrors } from '@hibanka/pg-utils';
try {
await User.insert({ id: 1 }); // typeorm, but it can be any other ORM or raw query
} catch (e) {
if (e.code === PgErrors.UNIQUE_VIOLATION) {
throw new Error('User with such id already exists');
}
throw e;
}