mirror of
https://github.com/ent/ent.git
synced 2026-04-28 05:30:56 +03:00
dialect/sql/sqlgraph: support nil errors in constraint checks (#3701)
* added nil checks to constraint errors * removed whitespace from nil error checks --------- Co-authored-by: Luc van Kessel <luc@klippa.com>
This commit is contained in:
@@ -18,6 +18,9 @@ func IsConstraintError(err error) bool {
|
||||
// IsUniqueConstraintError reports if the error resulted from a DB uniqueness constraint violation.
|
||||
// e.g. duplicate value in unique index.
|
||||
func IsUniqueConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
for _, s := range []string{
|
||||
"Error 1062", // MySQL
|
||||
"violates unique constraint", // Postgres
|
||||
@@ -33,6 +36,9 @@ func IsUniqueConstraintError(err error) bool {
|
||||
// IsForeignKeyConstraintError reports if the error resulted from a database foreign-key constraint violation.
|
||||
// e.g. parent row does not exist.
|
||||
func IsForeignKeyConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
for _, s := range []string{
|
||||
"Error 1451", // MySQL (Cannot delete or update a parent row).
|
||||
"Error 1452", // MySQL (Cannot add or update a child row).
|
||||
|
||||
Reference in New Issue
Block a user