dbutil

package
v0.3.13 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnhanceFilterQueryError

func EnhanceFilterQueryError(err error, filterQuery string) error

EnhanceFilterQueryError provides user-friendly error messages for common filter query parsing mistakes. Should be called when filter query parsing fails to give users helpful hints.

func IsDatabaseTypeConversionError

func IsDatabaseTypeConversionError(err error) bool

IsDatabaseTypeConversionError checks if a database error is caused by type conversion issues (e.g., trying to convert string "x" to a number) that should return 400 Bad Request instead of 500

func IsDuplicateKeyError

func IsDuplicateKeyError(err error) bool

IsDuplicateKeyError checks if a database error is caused by a unique constraint violation. Uses database-specific error codes for reliable detection across versions and locales. Returns true for both MySQL and PostgreSQL unique constraint errors.

Error codes used:

  • PostgreSQL: 23505 (unique_violation)
  • MySQL: 1062 (ER_DUP_ENTRY - duplicate entry for key)

References:

func QuoteTableName

func QuoteTableName(db *gorm.DB, tableName string) string

QuoteTableName quotes a table name based on database dialect to prevent SQL injection and handle reserved keywords properly.

func SanitizeDatabaseError

func SanitizeDatabaseError(err error) error

SanitizeDatabaseError checks if a database error is a type conversion error and converts it to a BadRequest error. Otherwise returns the original error. This prevents exposing internal database error details to users. Should be called after query execution to sanitize errors.

Types

This section is empty.

Jump to

Keyboard shortcuts

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