entc/gen: cleanup sql templates

This commit is contained in:
Ariel Mashraki
2021-06-27 10:15:42 +03:00
committed by Ariel Mashraki
parent b64f122afd
commit ded20a0e36
198 changed files with 676 additions and 907 deletions

View File

@@ -12,7 +12,6 @@ import (
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/examples/privacyadmin/ent/user"
)
@@ -262,10 +261,3 @@ func IsConstraintError(err error) bool {
var e *ConstraintError
return errors.As(err, &e)
}
func isSQLConstraintError(err error) (*ConstraintError, bool) {
if sqlgraph.IsConstraintError(err) {
return &ConstraintError{err.Error(), err}, true
}
return nil, false
}

View File

@@ -109,8 +109,8 @@ func (uc *UserCreate) check() error {
func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
_node, _spec := uc.createSpec()
if err := sqlgraph.CreateNode(ctx, uc.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{err.Error(), err}
}
return nil, err
}
@@ -172,8 +172,8 @@ func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) {
} else {
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, ucb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{err.Error(), err}
}
}
}

View File

@@ -128,8 +128,8 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{err.Error(), err}
}
return 0, err
}
@@ -269,8 +269,8 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error)
if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{err.Error(), err}
}
return nil, err
}