Documentation
¶
Overview ¶
Package pqerrors provides constants for pq's (github.com/lib/pq) ErrorClass and ErrorCode
ErrorClass constants are in the pqerrcls package and ErrorCode constants are in the pqerrcode package
Example ¶
package main import ( "fmt" "github.com/dhui/pqerrors/pqerrcls" "github.com/dhui/pqerrors/pqerrcode" "github.com/lib/pq" ) func main() { pqErr := pq.Error{Code: pq.ErrorCode("23505")} var err error = pqErr // err from database/sql if e, ok := err.(pq.Error); ok { // Example usage of pqerrcls switch e.Code.Class() { case pqerrcls.IntegrityConstraintViolation: fmt.Println("Class success!") default: fmt.Println("Unexpected error class:", e.Code.Class(), e.Code.Class().Name()) } // Example usage of pqerrcode switch e.Code { case pqerrcode.IntegrityConstraintViolationUniqueViolation: fmt.Println("Code success!") default: fmt.Println("Unexpected error code:", e.Code, e.Code.Name()) } } }
Output: Class success! Code success!
Click to show internal directories.
Click to hide internal directories.