MCPcopy
hub / github.com/ent/ent / IsUniqueConstraintError

Function IsUniqueConstraintError

dialect/sql/sqlgraph/errors.go:23–37  ·  view source on GitHub ↗

IsUniqueConstraintError reports if the error resulted from a DB uniqueness constraint violation. e.g. duplicate value in unique index.

(err error)

Source from the content-addressed store, hash-verified

21// IsUniqueConstraintError reports if the error resulted from a DB uniqueness constraint violation.
22// e.g. duplicate value in unique index.
23func IsUniqueConstraintError(err error) bool {
24 if err == nil {
25 return false
26 }
27 for _, s := range []string{
28 "Error 1062", // MySQL
29 "violates unique constraint", // Postgres
30 "UNIQUE constraint failed", // SQLite
31 } {
32 if strings.Contains(err.Error(), s) {
33 return true
34 }
35 }
36 return false
37}
38
39// IsForeignKeyConstraintError reports if the error resulted from a database foreign-key constraint violation.
40// e.g. parent row does not exist.

Callers 3

ConstraintChecksFunction · 0.92
TestIsConstraintErrorFunction · 0.85
IsConstraintErrorFunction · 0.85

Calls 2

ErrorMethod · 0.65
ContainsMethod · 0.45

Tested by 2

ConstraintChecksFunction · 0.74
TestIsConstraintErrorFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…