dbclassify

package
v1.28.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package dbclassify holds the per-driver error predicates.

It exists to have exactly one copy of each. Three places need them and they cannot all reach the same one otherwise: the driver modules under drivers/, the `nucleus` CLI (which links every engine, being a tool people point at whatever database they have), and the framework's own test binary. Written out three times they would drift — and a classifier that drifts does not fail, it answers false, which is a wrong answer nothing reports.

Nothing in the framework's runtime imports this package, and that is the point: importing it means importing the driver error types, which is the weight ADR-031 removed. The drivers-and-exporters CI lane asserts that pkg/app cannot reach any of them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MSSQLUniqueViolation

func MSSQLUniqueViolation(err error) bool

MSSQLUniqueViolation matches 2627 (unique/primary-key CONSTRAINT) and 2601 (duplicate row in a unique INDEX). Both exist because the engine raises a different number depending on how uniqueness was declared, and a caller cares about neither distinction.

mssqldb.Error has a value receiver on Error(), so errors.As must target the VALUE type — a pointer target never matches.

func MySQLUniqueViolation

func MySQLUniqueViolation(err error) bool

MySQLUniqueViolation matches error 1062 (ER_DUP_ENTRY) on the CODE, not on the message: a server running with lc_messages set to another language answers the same rejection in that language, and a substring check would silently return false there.

func OracleUniqueViolation

func OracleUniqueViolation(err error) bool

OracleUniqueViolation matches ORA-00001 ("unique constraint violated").

go-ora/v2 may return *network.OracleError directly or wrapped inside a *network.SessionError; errors.As walks the Unwrap chain, so one check covers both shapes — do not "simplify" this into a type switch.

func RegisterAll

func RegisterAll()

RegisterAll registers the classifier for every engine. PostgreSQL is absent on purpose: pkg/db reads its SQLSTATE through the method every PostgreSQL driver exposes, so it needs no registration — and registering one typed to pgx would quietly stop covering lib/pq.

func SQLiteUniqueViolation

func SQLiteUniqueViolation(err error) bool

SQLiteUniqueViolation matches SQLite's extended result codes: 2067 is SQLITE_CONSTRAINT_UNIQUE and 1555 SQLITE_CONSTRAINT_PRIMARYKEY. Both mean "that value is already taken"; the primary-key code is separate and would be missed by a check that only looked for the unique one.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL