37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
|
|
// Code generated by BobGen mysql v0.42.0. DO NOT EDIT.
|
||
|
|
// This file is meant to be re-generated in place and/or deleted at any time.
|
||
|
|
|
||
|
|
package dberrors
|
||
|
|
|
||
|
|
import (
|
||
|
|
"strings"
|
||
|
|
|
||
|
|
mysqlDriver "github.com/go-sql-driver/mysql"
|
||
|
|
)
|
||
|
|
|
||
|
|
// ErrUniqueConstraint captures all unique constraint errors by explicitly leaving `s` empty.
|
||
|
|
var ErrUniqueConstraint = &UniqueConstraintError{s: ""}
|
||
|
|
|
||
|
|
type UniqueConstraintError struct {
|
||
|
|
// schema is the schema where the unique constraint is defined.
|
||
|
|
schema string
|
||
|
|
// table is the name of the table where the unique constraint is defined.
|
||
|
|
table string
|
||
|
|
// columns are the columns constituting the unique constraint.
|
||
|
|
columns []string
|
||
|
|
// s is a string uniquely identifying the constraint in the raw error message returned from the database.
|
||
|
|
s string
|
||
|
|
}
|
||
|
|
|
||
|
|
func (e *UniqueConstraintError) Error() string {
|
||
|
|
return e.s
|
||
|
|
}
|
||
|
|
|
||
|
|
func (e *UniqueConstraintError) Is(target error) bool {
|
||
|
|
err, ok := target.(*mysqlDriver.MySQLError)
|
||
|
|
if !ok {
|
||
|
|
return false
|
||
|
|
}
|
||
|
|
return err.Number == 1062 && strings.Contains(err.Message, e.s)
|
||
|
|
}
|