mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
* entc/gen/template/dialect/sql: cleaning up isSQLConstraintError in generated ent.go to use new sqlgraph IsConstraintError checks. Adding IsFK and IsUniqueness methods to the generated ent.ConstraintError (on SQL dialects) struct to allow users to glean more information about the specific constraint violation. Fixes #1310 * fix indentation in tmpl file regen files rm new methods from generated code * regen
27 lines
779 B
Cheetah
27 lines
779 B
Cheetah
{{/*
|
|
Copyright 2019-present Facebook Inc. All rights reserved.
|
|
This source code is licensed under the Apache 2.0 license found
|
|
in the LICENSE file in the root directory of this source tree.
|
|
*/}}
|
|
|
|
{{/* custom errors and errors handlers for sql dialects */}}
|
|
{{ define "dialect/sql/errors" }}
|
|
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
return &ConstraintError{err.Error(), err}, true
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// 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("%w: %v", err, rerr)
|
|
}
|
|
if err, ok := isSQLConstraintError(err); ok {
|
|
return err
|
|
}
|
|
return err
|
|
}
|
|
{{ end }}
|