File tree Expand file tree Collapse file tree 3 files changed +8
-5
lines changed Expand file tree Collapse file tree 3 files changed +8
-5
lines changed Original file line number Diff line number Diff line change 6
6
"gorm.io/gorm"
7
7
)
8
8
9
- var errCodes = map [string ]int {
10
- "uniqueConstraint" : 2067 ,
9
+ var errCodes = map [int ]error {
10
+ 2067 : gorm .ErrDuplicatedKey ,
11
+ 768 : gorm .ErrForeignKeyViolated ,
11
12
}
12
13
13
14
type ErrMessage struct {
@@ -30,8 +31,8 @@ func (dialector Dialector) Translate(err error) error {
30
31
return err
31
32
}
32
33
33
- if errMsg . ExtendedCode == errCodes ["uniqueConstraint" ] {
34
- return gorm . ErrDuplicatedKey
34
+ if translatedErr , found := errCodes [errMsg . ExtendedCode ]; found {
35
+ return translatedErr
35
36
}
36
37
return err
37
38
}
Original file line number Diff line number Diff line change 4
4
5
5
require (
6
6
github.com/mattn/go-sqlite3 v1.14.17
7
- gorm.io/gorm v1.25.0
7
+ gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55
8
8
)
9
9
10
10
require (
Original file line number Diff line number Diff line change @@ -6,3 +6,5 @@ github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6
6
6
github.com/mattn/go-sqlite3 v1.14.17 /go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg =
7
7
gorm.io/gorm v1.25.0 h1:+KtYtb2roDz14EQe4bla8CbQlmb9dN3VejSai3lprfU =
8
8
gorm.io/gorm v1.25.0 /go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k =
9
+ gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55 h1:sC1Xj4TYrLqg1n3AN10w871An7wJM0gzgcm8jkIkECQ =
10
+ gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55 /go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k =
You can’t perform that action at this time.
0 commit comments