-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat: Unique Constraint Violation error translator for different drivers #6004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Unique Constraint Violation error translator for different drivers #6004
Conversation
Maybe we can add If the dialector implements |
This is a good idea, I will update the PR & also create a new PR for one of the drivers. |
c36db2a
to
d975b80
Compare
Hello, will this new |
I would like to know too! And while I'm at it, how should I go about updating my project dependencies to use the new gorm release that has this error included? |
Documentation has been added go-gorm/gorm.io#664 |
Remove common.ErrDBUniqueConstraint, which was used as a workaround for the lack of abstraction in gorm. With the update in go-gorm/gorm#6004 we can now fully use gorm for db related errors (fe. gorm.ErrDuplicatedKey).
Remove common.ErrDBUniqueConstraint, which was used as a workaround for the lack of abstraction in gorm. With the update in go-gorm/gorm#6004 we can now fully use gorm for db related errors (fe. gorm.ErrDuplicatedKey).
Remove common.ErrDBUniqueConstraint, which was used as a workaround for the lack of abstraction in gorm. With the update in go-gorm/gorm#6004 we can now fully use gorm for db related errors (fe. gorm.ErrDuplicatedKey).
Remove common.ErrDBUniqueConstraint, which was used as a workaround for the lack of abstraction in gorm. With the update in go-gorm/gorm#6004 we can now fully use gorm for db related errors (fe. gorm.ErrDuplicatedKey).
Remove common.ErrDBUniqueConstraint, which was used as a workaround for the lack of abstraction in gorm. With the update in go-gorm/gorm#6004 we can now fully use gorm for db related errors (fe. gorm.ErrDuplicatedKey).
Remove common.ErrDBUniqueConstraint, which was used as a workaround for the lack of abstraction in gorm. With the update in go-gorm/gorm#6004 we can now fully use gorm for db related errors (fe. gorm.ErrDuplicatedKey).
Remove common.ErrDBUniqueConstraint, which was used as a workaround for the lack of abstraction in gorm. With the update in go-gorm/gorm#6004 we can now fully use gorm for db related errors (fe. gorm.ErrDuplicatedKey).
Remove common.ErrDBUniqueConstraint, which was used as a workaround for the lack of abstraction in gorm. With the update in go-gorm/gorm#6004 we can now fully use gorm for db related errors (fe. gorm.ErrDuplicatedKey).
What did this pull request do?
It will enable developers to have a better error response when there is a unique key constraint violation detected in different SQL engines.
Addresses these issues: #4037, #4135, #5651, #6002.
There is no new import or any dependency on any driver, the implementation works by marshaling the returned error from any query and comparing it to SQL engine's default error message by looking after the error code.
User Case Description
When there is a unique key constraint violation error it will return
gorm.ErrDuplicatedKey
. Basically, it will look if there is a translation available for a specific type of error, if there was one it will return that translation, otherwise, it will return the given untranslated error.