sqlstore: add support for checking if error is constraint validation error

This commit is contained in:
Marcus Efraimsson
2018-09-27 13:38:22 +02:00
parent c5278af6c4
commit d093244282
9 changed files with 1156 additions and 19 deletions
@@ -6,6 +6,7 @@ import (
"strings"
"github.com/go-xorm/xorm"
"github.com/lib/pq"
)
type Postgres struct {
@@ -136,3 +137,13 @@ func (db *Postgres) CleanDB() error {
return nil
}
func (db *Postgres) IsUniqueConstraintViolation(err error) bool {
if driverErr, ok := err.(*pq.Error); ok {
if driverErr.Code == "23505" {
return true
}
}
return false
}