Socket
Socket
Sign inDemoInstall

pg-error-enum

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-error-enum

TypeScript Enum for Postgres Errors with no runtime dependencies


Version published
Weekly downloads
31K
increased by1.36%
Maintainers
1
Weekly downloads
 
Created
Source

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_]*)$/;
    

FAQs

Package last updated on 22 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc