MCPcopy
hub / github.com/ent/ent / IsConstraintError

Function IsConstraintError

dialect/sql/sqlgraph/errors.go:13–19  ·  view source on GitHub ↗

IsConstraintError returns true if the error resulted from a database constraint violation.

(err error)

Source from the content-addressed store, hash-verified

11
12// IsConstraintError returns true if the error resulted from a database constraint violation.
13func IsConstraintError(err error) bool {
14 var e *ConstraintError
15 return errors.As(err, &e) ||
16 IsUniqueConstraintError(err) ||
17 IsForeignKeyConstraintError(err) ||
18 IsCheckConstraintError(err)
19}
20
21// IsUniqueConstraintError reports if the error resulted from a DB uniqueness constraint violation.
22// e.g. duplicate value in unique index.

Callers 15

sqlExecMethod · 0.92
sqlSaveMethod · 0.92
sqlSaveMethod · 0.92
sqlExecMethod · 0.92
sqlSaveMethod · 0.92
SaveMethod · 0.92
sqlExecMethod · 0.92
sqlSaveMethod · 0.92
sqlSaveMethod · 0.92
sqlSaveMethod · 0.92
SaveMethod · 0.92
sqlExecMethod · 0.92

Calls 4

IsUniqueConstraintErrorFunction · 0.85
IsCheckConstraintErrorFunction · 0.85
AsMethod · 0.45

Tested by 1

TestIsConstraintErrorFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…