You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-library/vendor/gorm.io/driver/postgres/error_translator.go

21 lines
352 B

package postgres
import (
"github.com/jackc/pgx/v5/pgconn"
"gorm.io/gorm"
)
var errCodes = map[string]string{
"uniqueConstraint": "23505",
}
func (dialector Dialector) Translate(err error) error {
if pgErr, ok := err.(*pgconn.PgError); ok {
if pgErr.Code == errCodes["uniqueConstraint"] {
return gorm.ErrDuplicatedKey
}
}
return err
}