Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dialect/sql/sqlgraph/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).
Expand Down