Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = New(CodeNotFound, "record not found")
ErrNotFound is a convenience sentinel for not-found errors.
var ErrUniqueViolation = New(CodeUniqueViolation, "unique constraint violated")
ErrUniqueViolation is a convenience sentinel for unique constraint violations.
Functions ¶
func Is ¶
Is checks if the error matches a specific error code. It walks the error chain using errors.As to find a *DBError and compares its Code field.
func IsConnectionError ¶
IsConnectionError reports whether err is a DBError with CodeConnectionError.
func IsForeignKeyViolation ¶
IsForeignKeyViolation reports whether err is a DBError with CodeForeignKeyViolation.
func IsNotFound ¶
IsNotFound reports whether err is a DBError with CodeNotFound.
func IsUniqueViolation ¶
IsUniqueViolation reports whether err is a DBError with CodeUniqueViolation.
Types ¶
type DBError ¶
type DBError struct {
// Code is the classified error category.
Code ErrorCode
// Message is a user-friendly error message.
Message string
// Detail provides additional diagnostic context.
Detail string
// Cause is the original error from the database driver.
Cause error
// Meta holds additional metadata (e.g., constraint name, table, column).
Meta map[string]string
}
DBError is the unified ORM error type that wraps raw database errors with classification, context, and user-friendly messaging.
func (*DBError) Error ¶
Error returns a formatted error string including the code, message, detail (if present), and cause (if present).
func (*DBError) WithDetail ¶
WithDetail returns a copy of the error with a detail message.