Documentation
¶
Overview ¶
Package gormx translates database errors into the application's error vocabulary, and provides the query scopes every repository needs.
The translation is the valuable half. A driver error reaching a handler has two failure modes, and both are real: it is rendered as a 500 when it was actually a duplicate name the user can fix, and its text — containing the constraint name, the table and sometimes the value — is sent to the client.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNotFound ¶
IsNotFound reports whether err is GORM's not-found.
Types ¶
type Scope ¶
Scope is a composable query fragment.
func ForUpdate ¶
func ForUpdate() Scope
ForUpdate takes a row lock for the rest of the transaction.
Use it for read-modify-write on a counter, a quota or an allocation. The alternative — read, decide, write — is a lost update under any concurrency at all, and the window is wide enough to hit in practice.
func Paginate ¶
func Paginate(q pagination.Query) Scope
Paginate applies LIMIT, OFFSET and ORDER BY from a parsed page request.
The ORDER BY is only safe because pagination.Query.Sort is restricted to an allow-list at parse time. Never hand this a sort key straight off a request.