This commit is contained in:
jdl
2024-11-11 06:36:55 +01:00
parent d0587cc585
commit c5419d662e
102 changed files with 4181 additions and 0 deletions

31
pgutil/errors.go Normal file
View File

@@ -0,0 +1,31 @@
package pgutil
import (
"errors"
"github.com/lib/pq"
)
func ErrIsDuplicateKey(err error) bool {
return ErrHasCode(err, "23505")
}
func ErrIsForeignKey(err error) bool {
return ErrHasCode(err, "23503")
}
func ErrIsSerializationFaiilure(err error) bool {
return ErrHasCode(err, "40001")
}
func ErrHasCode(err error, code string) bool {
if err == nil {
return false
}
var pErr *pq.Error
if errors.As(err, &pErr) {
return pErr.Code == pq.ErrorCode(code)
}
return false
}