chore: update ent
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
This commit is contained in:
@@ -5,12 +5,11 @@ package db
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/dialect"
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
// ent aliases to avoid import conflicts in user's code.
|
||||
@@ -238,22 +237,8 @@ func IsConstraintError(err error) bool {
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
errors = [...]string{
|
||||
"Error 1062", // MySQL 1062 error (ER_DUP_ENTRY).
|
||||
"UNIQUE constraint failed", // SQLite.
|
||||
"duplicate key value violates unique constraint", // PostgreSQL.
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
return &ConstraintError{err.Error(), err}, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
@@ -261,7 +246,7 @@ func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
// rollback calls tx.Rollback and wraps the given error with the rollback error if present.
|
||||
func rollback(tx dialect.Tx, err error) error {
|
||||
if rerr := tx.Rollback(); rerr != nil {
|
||||
err = fmt.Errorf("%s: %v", err.Error(), rerr)
|
||||
err = fmt.Errorf("%w: %v", err, rerr)
|
||||
}
|
||||
if err, ok := isSQLConstraintError(err); ok {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user