Skip to content

A tiny Go package for checking errors returned by pgx, a Go driver for PostgreSQL.

License

Notifications You must be signed in to change notification settings

orsinium-labs/pgerrs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgerrs

A tiny Go package for checking errors returned by pgx, a Go driver for PostgreSQL.

Installation

go get github.com/orsinium-labs/pgerrs

Usage

if pgerrs.Is(err, pgerrs.CheckViolation) {
    println("violates a CHECK")
}

if pgerrs.ViolatesForeignKeyConstraint(err, "users", "address_id") {
    println("cannot add user, invalid address_id")
}

if pgerrs.ViolatesUniqueConstraint(err, "users", "email") {
    println("user with the given email already exists")
}

if pgerrs.ViolatesConstraint(err, "connections_from_to_key") {
    println("there can be only one connection with the given `from` and `to`")
}

About

A tiny Go package for checking errors returned by pgx, a Go driver for PostgreSQL.

Topics

Resources

License

Stars

Watchers

Forks

Languages