Documentation
¶
Overview ¶
Package dbutil provides small generic helpers around GORM that consolidate repetitive single-row lookup and transaction boilerplate found across services.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FirstWhere ¶
func FirstWhere[T any](ctx context.Context, db *gorm.DB, notFound error, where string, args ...any) (*T, error)
FirstWhere fetches a single row of T matching the provided WHERE clause. It maps gorm.ErrRecordNotFound to notFound (when non-nil) and otherwise wraps the error with a generic "failed to query <T>" prefix.
Example:
user, err := dbutil.FirstWhere[models.User](ctx, s.db.DB, ErrUserNotFound, "username = ?", username)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.