hiling_go/db/sqlc/error.go
2024-05-22 11:26:15 +07:00

28 lines
404 B
Go
Executable File

package db
import (
"errors"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
)
const (
ForeignKeyViolation = "23503"
UniqueViolation = "23505"
)
var ErrRecordNotFound = pgx.ErrNoRows
var ErrUniqueViolation = &pgconn.PgError{
Code: UniqueViolation,
}
func ErrorCode(err error) string {
var pgErr *pgconn.PgError
if errors.As(err, &pgErr) {
return pgErr.Code
}
return ""
}