/** * Database error type definitions. * * @packageDocumentation */ /** * Database error classification. * * @remarks * Categorizes database errors for consistent error handling across adapters. * Each adapter translates database-specific error codes to these kinds. * * @public */ type DatabaseErrorKind = "connection" | "query" | "constraint" | "unique_violation" | "foreign_key_violation" | "check_violation" | "not_null_violation" | "deadlock" | "timeout" | "serialization_failure" | "unsupported_version" | "unknown"; /** * Enhanced database error interface. * * @remarks * Extends the standard Error interface with database-specific context. * Adapters should throw errors implementing this interface for consistent * error handling. * * @example * ```typescript * try { * await adapter.insert('users', { email: 'duplicate@example.com' }); * } catch (error) { * if (isDatabaseError(error) && error.kind === 'unique_violation') { * console.log(`Duplicate ${error.column} in ${error.table}`); * } * } * ``` * * @public */ interface DatabaseError extends Error { /** Error classification */ kind: DatabaseErrorKind; /** Database-specific error code (e.g., "23505" for PostgreSQL unique violation) */ code?: string; /** Constraint name that was violated (if applicable) */ constraint?: string; /** Table name involved in the error */ table?: string; /** Column name involved in the error */ column?: string; /** Detailed error description from the database */ detail?: string; /** Hint for resolving the error */ hint?: string; /** Original error from the database driver */ cause?: Error; } /** * Type guard for DatabaseError. * * @remarks * Checks if an error is a DatabaseError with proper typing. * * @param error - Error to check * @returns True if error is a DatabaseError * * @public */ declare function isDatabaseError(error: unknown): error is DatabaseError; /** * Database error constructor options. * * @public */ interface DatabaseErrorOptions { /** Error classification */ kind: DatabaseErrorKind; /** Error message */ message: string; /** Database-specific error code */ code?: string; /** Constraint name */ constraint?: string; /** Table name */ table?: string; /** Column name */ column?: string; /** Detailed description */ detail?: string; /** Resolution hint */ hint?: string; /** Original error */ cause?: Error; } /** * Create a DatabaseError instance. * * @remarks * Helper function to create properly structured DatabaseError objects. * * @param options - Error options * @returns DatabaseError instance * * @public */ declare function createDatabaseError(options: DatabaseErrorOptions): DatabaseError; export { type DatabaseErrorKind as D, type DatabaseError as a, type DatabaseErrorOptions as b, createDatabaseError as c, isDatabaseError as i };