0.7.1 • Published 3 months ago

pg-error-enum v0.7.1

Weekly downloads
57
License
MIT
Repository
github
Last release
3 months ago

pg-error-enum

npm version build status

TypeScript Enum for Postgres Errors with no runtime dependencies. Also compatible with plain JavaScript.

Quick Start

Installation

# Using npm
npm install --save pg-error-enum

# Using yarn
yarn add pg-error-enum

Usage

TypeScript or ES6 Modules

import { PostgresError } from "pg-error-enum";

JavaScript

const PostgresError = require("pg-error-enum").PostgresError;

Usage

if (error.code === PostgresError.UNIQUE_VIOLATION) {
  throw new Error("That username is taken");
}

Generation

The Enum is generated directly from errcodes.txt in the Postgres repository.

It follows the syntax defined in the text file, i.e., in short:

  1. Lines beginning with # and empty lines are ignored.

  2. Sections are parsed using:

    const sectionRegex = /^Section:\s(?<description>.*)$/;
  3. Each error code is parsed using:

    const errorLineRegex =
      /^(?<sqlstate>[A-Z0-9]*)\s*(?<severity>[EWS])\s*ERRCODE_(?<constant>[A-Z_]*)\s*(?<code>[a-z_]*)$/;
0.7.1

3 months ago

0.7.0

8 months ago

0.6.1

10 months ago

0.6.0

2 years ago

0.5.0

3 years ago

0.4.0

4 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago