mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
all: use more go-ish error for constraint failures
This commit is contained in:
@@ -110,9 +110,7 @@ func (cc *CityCreate) sqlSave(ctx context.Context) (*City, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
c.ID = int(id)
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ func (cu *CityUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
return 0, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(cu.streets) {
|
||||
return 0, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"streets\" %v already connected to a different \"City\"", keys(cu.streets))})
|
||||
return 0, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"streets\" %v already connected to a different \"City\"", keys(cu.streets))})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -354,7 +354,7 @@ func (cuo *CityUpdateOne) sqlSave(ctx context.Context) (c *City, err error) {
|
||||
return nil, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(cuo.streets) {
|
||||
return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"streets\" %v already connected to a different \"City\"", keys(cuo.streets))})
|
||||
return nil, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"streets\" %v already connected to a different \"City\"", keys(cuo.streets))})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,30 +127,31 @@ func IsNotSingular(err error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// ErrConstraintFailed returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or field uniqueness.
|
||||
type ErrConstraintFailed struct {
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ErrConstraintFailed) Error() string {
|
||||
return fmt.Sprintf("ent: unique constraint failed: %s", e.msg)
|
||||
func (e ConstraintError) Error() string {
|
||||
return fmt.Sprintf("ent: constraint failed: %s", e.msg)
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ErrConstraintFailed) Unwrap() error {
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintFailure(err error) bool {
|
||||
_, ok := err.(*ErrConstraintFailed)
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
_, ok := err.(*ConstraintError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
@@ -161,11 +162,11 @@ func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
|
||||
@@ -115,9 +115,7 @@ func (sc *StreetCreate) sqlSave(ctx context.Context) (*Street, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
s.ID = int(id)
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@@ -127,30 +127,31 @@ func IsNotSingular(err error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// ErrConstraintFailed returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or field uniqueness.
|
||||
type ErrConstraintFailed struct {
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ErrConstraintFailed) Error() string {
|
||||
return fmt.Sprintf("ent: unique constraint failed: %s", e.msg)
|
||||
func (e ConstraintError) Error() string {
|
||||
return fmt.Sprintf("ent: constraint failed: %s", e.msg)
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ErrConstraintFailed) Unwrap() error {
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintFailure(err error) bool {
|
||||
_, ok := err.(*ErrConstraintFailed)
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
_, ok := err.(*ConstraintError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
@@ -161,11 +162,11 @@ func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
|
||||
@@ -50,9 +50,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
u.ID = int(id)
|
||||
|
||||
return u, nil
|
||||
}
|
||||
|
||||
@@ -127,30 +127,31 @@ func IsNotSingular(err error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// ErrConstraintFailed returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or field uniqueness.
|
||||
type ErrConstraintFailed struct {
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ErrConstraintFailed) Error() string {
|
||||
return fmt.Sprintf("ent: unique constraint failed: %s", e.msg)
|
||||
func (e ConstraintError) Error() string {
|
||||
return fmt.Sprintf("ent: constraint failed: %s", e.msg)
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ErrConstraintFailed) Unwrap() error {
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintFailure(err error) bool {
|
||||
_, ok := err.(*ErrConstraintFailed)
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
_, ok := err.(*ConstraintError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
@@ -161,11 +162,11 @@ func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
|
||||
@@ -110,9 +110,7 @@ func (gc *GroupCreate) sqlSave(ctx context.Context) (*Group, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
gr.ID = int(id)
|
||||
|
||||
return gr, nil
|
||||
}
|
||||
|
||||
@@ -128,9 +128,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
u.ID = int(id)
|
||||
|
||||
return u, nil
|
||||
}
|
||||
|
||||
@@ -127,30 +127,31 @@ func IsNotSingular(err error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// ErrConstraintFailed returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or field uniqueness.
|
||||
type ErrConstraintFailed struct {
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ErrConstraintFailed) Error() string {
|
||||
return fmt.Sprintf("ent: unique constraint failed: %s", e.msg)
|
||||
func (e ConstraintError) Error() string {
|
||||
return fmt.Sprintf("ent: constraint failed: %s", e.msg)
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ErrConstraintFailed) Unwrap() error {
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintFailure(err error) bool {
|
||||
_, ok := err.(*ErrConstraintFailed)
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
_, ok := err.(*ConstraintError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
@@ -161,11 +162,11 @@ func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
|
||||
@@ -127,9 +127,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
u.ID = int(id)
|
||||
|
||||
return u, nil
|
||||
}
|
||||
|
||||
@@ -127,30 +127,31 @@ func IsNotSingular(err error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// ErrConstraintFailed returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or field uniqueness.
|
||||
type ErrConstraintFailed struct {
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ErrConstraintFailed) Error() string {
|
||||
return fmt.Sprintf("ent: unique constraint failed: %s", e.msg)
|
||||
func (e ConstraintError) Error() string {
|
||||
return fmt.Sprintf("ent: constraint failed: %s", e.msg)
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ErrConstraintFailed) Unwrap() error {
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintFailure(err error) bool {
|
||||
_, ok := err.(*ErrConstraintFailed)
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
_, ok := err.(*ConstraintError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
@@ -161,11 +162,11 @@ func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
|
||||
@@ -167,9 +167,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
u.ID = int(id)
|
||||
|
||||
return u, nil
|
||||
}
|
||||
|
||||
@@ -127,30 +127,31 @@ func IsNotSingular(err error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// ErrConstraintFailed returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or field uniqueness.
|
||||
type ErrConstraintFailed struct {
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ErrConstraintFailed) Error() string {
|
||||
return fmt.Sprintf("ent: unique constraint failed: %s", e.msg)
|
||||
func (e ConstraintError) Error() string {
|
||||
return fmt.Sprintf("ent: constraint failed: %s", e.msg)
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ErrConstraintFailed) Unwrap() error {
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintFailure(err error) bool {
|
||||
_, ok := err.(*ErrConstraintFailed)
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
_, ok := err.(*ConstraintError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
@@ -161,11 +162,11 @@ func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
|
||||
@@ -115,9 +115,7 @@ func (pc *PetCreate) sqlSave(ctx context.Context) (*Pet, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
pe.ID = int(id)
|
||||
|
||||
return pe, nil
|
||||
}
|
||||
|
||||
@@ -128,9 +128,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
u.ID = int(id)
|
||||
|
||||
return u, nil
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
return 0, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(uu.pets) {
|
||||
return 0, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"pets\" %v already connected to a different \"User\"", keys(uu.pets))})
|
||||
return 0, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"pets\" %v already connected to a different \"User\"", keys(uu.pets))})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -406,7 +406,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
|
||||
return nil, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(uuo.pets) {
|
||||
return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"pets\" %v already connected to a different \"User\"", keys(uuo.pets))})
|
||||
return nil, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"pets\" %v already connected to a different \"User\"", keys(uuo.pets))})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,30 +127,31 @@ func IsNotSingular(err error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// ErrConstraintFailed returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or field uniqueness.
|
||||
type ErrConstraintFailed struct {
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ErrConstraintFailed) Error() string {
|
||||
return fmt.Sprintf("ent: unique constraint failed: %s", e.msg)
|
||||
func (e ConstraintError) Error() string {
|
||||
return fmt.Sprintf("ent: constraint failed: %s", e.msg)
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ErrConstraintFailed) Unwrap() error {
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintFailure(err error) bool {
|
||||
_, ok := err.(*ErrConstraintFailed)
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
_, ok := err.(*ConstraintError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
@@ -161,11 +162,11 @@ func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
|
||||
@@ -154,9 +154,7 @@ func (nc *NodeCreate) sqlSave(ctx context.Context) (*Node, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
n.ID = int(id)
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ func (nu *NodeUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
return 0, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(nu.children) {
|
||||
return 0, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"children\" %v already connected to a different \"Node\"", keys(nu.children))})
|
||||
return 0, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"children\" %v already connected to a different \"Node\"", keys(nu.children))})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -491,7 +491,7 @@ func (nuo *NodeUpdateOne) sqlSave(ctx context.Context) (n *Node, err error) {
|
||||
return nil, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(nuo.children) {
|
||||
return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"children\" %v already connected to a different \"Node\"", keys(nuo.children))})
|
||||
return nil, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"children\" %v already connected to a different \"Node\"", keys(nuo.children))})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,9 +129,7 @@ func (cc *CardCreate) sqlSave(ctx context.Context) (*Card, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
c.ID = int(id)
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ func (cu *CardUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
return 0, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(cu.owner) {
|
||||
return 0, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"owner\" %v already connected to a different \"Card\"", keys(cu.owner))})
|
||||
return 0, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"owner\" %v already connected to a different \"Card\"", keys(cu.owner))})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -333,7 +333,7 @@ func (cuo *CardUpdateOne) sqlSave(ctx context.Context) (c *Card, err error) {
|
||||
return nil, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(cuo.owner) {
|
||||
return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"owner\" %v already connected to a different \"Card\"", keys(cuo.owner))})
|
||||
return nil, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"owner\" %v already connected to a different \"Card\"", keys(cuo.owner))})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,30 +127,31 @@ func IsNotSingular(err error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// ErrConstraintFailed returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or field uniqueness.
|
||||
type ErrConstraintFailed struct {
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ErrConstraintFailed) Error() string {
|
||||
return fmt.Sprintf("ent: unique constraint failed: %s", e.msg)
|
||||
func (e ConstraintError) Error() string {
|
||||
return fmt.Sprintf("ent: constraint failed: %s", e.msg)
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ErrConstraintFailed) Unwrap() error {
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintFailure(err error) bool {
|
||||
_, ok := err.(*ErrConstraintFailed)
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
_, ok := err.(*ConstraintError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
@@ -161,11 +162,11 @@ func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
|
||||
@@ -133,9 +133,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
u.ID = int(id)
|
||||
|
||||
return u, nil
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
return 0, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(uu.card) {
|
||||
return 0, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"card\" %v already connected to a different \"User\"", keys(uu.card))})
|
||||
return 0, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"card\" %v already connected to a different \"User\"", keys(uu.card))})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,7 +373,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
|
||||
return nil, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(uuo.card) {
|
||||
return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"card\" %v already connected to a different \"User\"", keys(uuo.card))})
|
||||
return nil, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"card\" %v already connected to a different \"User\"", keys(uuo.card))})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,30 +127,31 @@ func IsNotSingular(err error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// ErrConstraintFailed returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or field uniqueness.
|
||||
type ErrConstraintFailed struct {
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ErrConstraintFailed) Error() string {
|
||||
return fmt.Sprintf("ent: unique constraint failed: %s", e.msg)
|
||||
func (e ConstraintError) Error() string {
|
||||
return fmt.Sprintf("ent: constraint failed: %s", e.msg)
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ErrConstraintFailed) Unwrap() error {
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintFailure(err error) bool {
|
||||
_, ok := err.(*ErrConstraintFailed)
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
_, ok := err.(*ConstraintError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
@@ -161,11 +162,11 @@ func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
|
||||
@@ -132,9 +132,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
u.ID = int(id)
|
||||
|
||||
return u, nil
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
return 0, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(uu.spouse) {
|
||||
return 0, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("\"spouse\" (%v) already connected to a different \"User\"", eid)})
|
||||
return 0, rollback(tx, &ConstraintError{msg: fmt.Sprintf("\"spouse\" (%v) already connected to a different \"User\"", eid)})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -400,7 +400,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
|
||||
return nil, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(uuo.spouse) {
|
||||
return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("\"spouse\" (%v) already connected to a different \"User\"", eid)})
|
||||
return nil, rollback(tx, &ConstraintError{msg: fmt.Sprintf("\"spouse\" (%v) already connected to a different \"User\"", eid)})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,30 +127,31 @@ func IsNotSingular(err error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// ErrConstraintFailed returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or field uniqueness.
|
||||
type ErrConstraintFailed struct {
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ErrConstraintFailed) Error() string {
|
||||
return fmt.Sprintf("ent: unique constraint failed: %s", e.msg)
|
||||
func (e ConstraintError) Error() string {
|
||||
return fmt.Sprintf("ent: constraint failed: %s", e.msg)
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ErrConstraintFailed) Unwrap() error {
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintFailure(err error) bool {
|
||||
_, ok := err.(*ErrConstraintFailed)
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
_, ok := err.(*ConstraintError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
@@ -161,11 +162,11 @@ func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
|
||||
@@ -159,9 +159,7 @@ func (nc *NodeCreate) sqlSave(ctx context.Context) (*Node, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
n.ID = int(id)
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ func (nu *NodeUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
return 0, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(nu.prev) {
|
||||
return 0, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"prev\" %v already connected to a different \"Node\"", keys(nu.prev))})
|
||||
return 0, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"prev\" %v already connected to a different \"Node\"", keys(nu.prev))})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,7 +240,7 @@ func (nu *NodeUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
return 0, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(nu.next) {
|
||||
return 0, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"next\" %v already connected to a different \"Node\"", keys(nu.next))})
|
||||
return 0, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"next\" %v already connected to a different \"Node\"", keys(nu.next))})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -445,7 +445,7 @@ func (nuo *NodeUpdateOne) sqlSave(ctx context.Context) (n *Node, err error) {
|
||||
return nil, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(nuo.prev) {
|
||||
return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"prev\" %v already connected to a different \"Node\"", keys(nuo.prev))})
|
||||
return nil, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"prev\" %v already connected to a different \"Node\"", keys(nuo.prev))})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -473,7 +473,7 @@ func (nuo *NodeUpdateOne) sqlSave(ctx context.Context) (n *Node, err error) {
|
||||
return nil, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(nuo.next) {
|
||||
return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"next\" %v already connected to a different \"Node\"", keys(nuo.next))})
|
||||
return nil, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"next\" %v already connected to a different \"Node\"", keys(nuo.next))})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,9 +134,7 @@ func (cc *CarCreate) sqlSave(ctx context.Context) (*Car, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
c.ID = int(id)
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
@@ -127,30 +127,31 @@ func IsNotSingular(err error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// ErrConstraintFailed returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or field uniqueness.
|
||||
type ErrConstraintFailed struct {
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ErrConstraintFailed) Error() string {
|
||||
return fmt.Sprintf("ent: unique constraint failed: %s", e.msg)
|
||||
func (e ConstraintError) Error() string {
|
||||
return fmt.Sprintf("ent: constraint failed: %s", e.msg)
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ErrConstraintFailed) Unwrap() error {
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintFailure(err error) bool {
|
||||
_, ok := err.(*ErrConstraintFailed)
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
_, ok := err.(*ConstraintError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
@@ -161,11 +162,11 @@ func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
|
||||
@@ -114,9 +114,7 @@ func (gc *GroupCreate) sqlSave(ctx context.Context) (*Group, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
gr.ID = int(id)
|
||||
|
||||
return gr, nil
|
||||
}
|
||||
|
||||
@@ -182,9 +182,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
u.ID = int(id)
|
||||
|
||||
return u, nil
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
return 0, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(uu.cars) {
|
||||
return 0, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"cars\" %v already connected to a different \"User\"", keys(uu.cars))})
|
||||
return 0, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"cars\" %v already connected to a different \"User\"", keys(uu.cars))})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -546,7 +546,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
|
||||
return nil, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(uuo.cars) {
|
||||
return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"cars\" %v already connected to a different \"User\"", keys(uuo.cars))})
|
||||
return nil, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"cars\" %v already connected to a different \"User\"", keys(uuo.cars))})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,30 +127,31 @@ func IsNotSingular(err error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// ErrConstraintFailed returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or field uniqueness.
|
||||
type ErrConstraintFailed struct {
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ErrConstraintFailed) Error() string {
|
||||
return fmt.Sprintf("ent: unique constraint failed: %s", e.msg)
|
||||
func (e ConstraintError) Error() string {
|
||||
return fmt.Sprintf("ent: constraint failed: %s", e.msg)
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ErrConstraintFailed) Unwrap() error {
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintFailure(err error) bool {
|
||||
_, ok := err.(*ErrConstraintFailed)
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
_, ok := err.(*ConstraintError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
@@ -161,11 +162,11 @@ func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
|
||||
@@ -155,9 +155,7 @@ func (gc *GroupCreate) sqlSave(ctx context.Context) (*Group, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
gr.ID = int(id)
|
||||
|
||||
return gr, nil
|
||||
}
|
||||
|
||||
@@ -155,9 +155,7 @@ func (pc *PetCreate) sqlSave(ctx context.Context) (*Pet, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
pe.ID = int(id)
|
||||
|
||||
return pe, nil
|
||||
}
|
||||
|
||||
@@ -249,9 +249,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := spec.ID.Value.(int64)
|
||||
u.ID = int(id)
|
||||
|
||||
return u, nil
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
return 0, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(uu.pets) {
|
||||
return 0, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"pets\" %v already connected to a different \"User\"", keys(uu.pets))})
|
||||
return 0, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"pets\" %v already connected to a different \"User\"", keys(uu.pets))})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -436,7 +436,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
return 0, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(uu.manage) {
|
||||
return 0, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"manage\" %v already connected to a different \"User\"", keys(uu.manage))})
|
||||
return 0, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"manage\" %v already connected to a different \"User\"", keys(uu.manage))})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -762,7 +762,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
|
||||
return nil, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(uuo.pets) {
|
||||
return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"pets\" %v already connected to a different \"User\"", keys(uuo.pets))})
|
||||
return nil, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"pets\" %v already connected to a different \"User\"", keys(uuo.pets))})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -865,7 +865,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
|
||||
return nil, rollback(tx, err)
|
||||
}
|
||||
if int(affected) < len(uuo.manage) {
|
||||
return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"manage\" %v already connected to a different \"User\"", keys(uuo.manage))})
|
||||
return nil, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"manage\" %v already connected to a different \"User\"", keys(uuo.manage))})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user