MCPcopy
hub / github.com/ent/ent / IsCheckConstraintError

Function IsCheckConstraintError

dialect/sql/sqlgraph/errors.go:60–74  ·  view source on GitHub ↗

IsCheckConstraintError reports if the error resulted from a database check constraint violation. e.g. a value does not satisfy a check condition.

(err error)

Source from the content-addressed store, hash-verified

58// IsCheckConstraintError reports if the error resulted from a database check constraint violation.
59// e.g. a value does not satisfy a check condition.
60func 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}

Callers 2

TestIsConstraintErrorFunction · 0.85
IsConstraintErrorFunction · 0.85

Calls 2

ErrorMethod · 0.65
ContainsMethod · 0.45

Tested by 1

TestIsConstraintErrorFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…