You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a dedicated method to extract error from errRow. This is already present for errRows. This allows the use case to extract the error to retry if necessary.
type errRow interface {
pgx.Row
Err() error
}
func (r *RetriableDBTX) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row {
row := r.dbtx.QueryRow(ctx, sql, args...)
if er, ok := row.(errRow); ok {
// Custom logic to retry
}
return row
}
My initial idea was to create a RetriableDBTX with the same interface as an entry-point for sqlc and to retry the method in case of an error. It's working for Exec and Query but I don't have any error for QueryRow and so my idea to be able to retrieve the error if we have an Err() error method. The Scan method is executed afterward by sqlc for each SQL query so it's much harder to perform the retry logic here.
This change won't do what you want. And what you are doing with Query() isn't reliable either.
Query() will only return an error in limited circumstances such as a network failure sending the request. The returned Rows has to be closed and Err() checked to know if it successfully ran.
QueryRow() is a very simple wrapper around Query(). The result isn't actually read until Scan() is called.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a dedicated method to extract error from
errRow. This is already present forerrRows. This allows the use case to extract the error to retry if necessary.