diff --git a/core/clients/db/dberr/codes.go b/core/clients/db/dberr/codes.go new file mode 100644 index 0000000..9cea769 --- /dev/null +++ b/core/clients/db/dberr/codes.go @@ -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 +}