common.go 420 B

123456789101112131415161718192021222324
  1. package repositories
  2. import "github.com/lib/pq"
  3. const (
  4. FKViolationErrorCode = "23503"
  5. DuplicateKeyErrorCode = "23505"
  6. )
  7. func IsFKViolationError(err error) bool {
  8. if pgErr, ok := err.(*pq.Error); ok {
  9. return pgErr.Code == FKViolationErrorCode
  10. }
  11. return false
  12. }
  13. func IsDuplicateKeyError(err error) bool {
  14. if pgErr, ok := err.(*pq.Error); ok {
  15. return pgErr.Code == DuplicateKeyErrorCode
  16. }
  17. return false
  18. }