Skip to content

Commit

Permalink
Merge pull request #35 from DrOctavius/main
Browse files Browse the repository at this point in the history
db client error codes
  • Loading branch information
DrOctavius authored Mar 29, 2023
2 parents fd518b9 + dc01585 commit 1484e0b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions core/clients/db/dberr/codes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dberr

import (
"errors"
"github.com/go-sql-driver/mysql"
"github.com/jackc/pgx/v5/pgconn"
)

func IsDuplicateKey(_err error) bool {
if pgError := _err.(*pgconn.PgError); errors.Is(_err, pgError) {
switch pgError.Code {
case "23505":
return true
}
} else if mysqlErr := _err.(*mysql.MySQLError); errors.Is(_err, mysqlErr) {
switch mysqlErr.Number {
case 1062:
return true
}
}
return false
}

0 comments on commit 1484e0b

Please sign in to comment.