IsCheckViolation checks if the error is due to a check violation. If one or more specific check constraints are given as arguments, the error must be caused by one of them. If no constraints are given, this function returns true for any check violation.
(err error, checkConstraints ...CheckConstraint)
| 64 | // caused by one of them. If no constraints are given, this function returns |
| 65 | // true for any check violation. |
| 66 | func IsCheckViolation(err error, checkConstraints ...CheckConstraint) bool { |
| 67 | var pqErr *pq.Error |
| 68 | if errors.As(err, &pqErr) { |
| 69 | if pqErr.Code.Name() == "check_violation" { |
| 70 | if len(checkConstraints) == 0 { |
| 71 | return true |
| 72 | } |
| 73 | for _, cc := range checkConstraints { |
| 74 | if pqErr.Constraint == string(cc) { |
| 75 | return true |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return false |
| 82 | } |
| 83 | |
| 84 | // IsQueryCanceledError checks if the error is due to a query being canceled. |
| 85 | func IsQueryCanceledError(err error) bool { |