IsCheckConstraintError reports if the error resulted from a database check constraint violation. e.g. a value does not satisfy a check condition.
(err error)
| 58 | // IsCheckConstraintError reports if the error resulted from a database check constraint violation. |
| 59 | // e.g. a value does not satisfy a check condition. |
| 60 | func IsCheckConstraintError(err error) bool { |
| 61 | if err == nil { |
| 62 | return false |
| 63 | } |
| 64 | for _, s := range []string{ |
| 65 | "Error 3819", // MySQL |
| 66 | "violates check constraint", // Postgres |
| 67 | "CHECK constraint failed", // SQLite |
| 68 | } { |
| 69 | if strings.Contains(err.Error(), s) { |
| 70 | return true |
| 71 | } |
| 72 | } |
| 73 | return false |
| 74 | } |
searching dependent graphs…