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
Is your feature request related to a problem? Please describe.
I've got a SQL consuming application that uses a different database driver based on build target. My check for an empty result uses errors.Is(err, sql.ErrNoRows), but this doesn't work with pgx, since it returns pgx.ErrNoRows.
Describe the solution you'd like
Since errors.Is unwraps errors, having pgx.ErrNoRows unwrap into a sql.ErrNoRows would make Is (and as a side-benefit, As) work for both pgx and sql errors, while still returning pgx.ErrNoRows. This can be done while keeping the string content and current behavior of errors.Is(err, pgx.ErrNoRows)
Describe alternatives you've considered
Having my DB implementations wrap the pgx-returned errors with an application-specific equivalent of "no rows" before leaving the DB interface and checking against that works (and is what I'm doing currently), but requires extra boilerplate.
I could also eschew the pgx interface and just use database/sql, but I'm using pgxpool, and I'm not sure if there's a way to access the native DB interface from a *pgxpool.Pool.
Additional context
None that I can think of.
The text was updated successfully, but these errors were encountered:
jessdwitch
changed the title
Have pgx.ErrNoRows nest sql.ErrNoRows
Have pgx.ErrNoRows wrap sql.ErrNoRows
Mar 6, 2024
Is your feature request related to a problem? Please describe.
I've got a SQL consuming application that uses a different database driver based on build target. My check for an empty result uses
errors.Is(err, sql.ErrNoRows)
, but this doesn't work with pgx, since it returnspgx.ErrNoRows
.Describe the solution you'd like
Since
errors.Is
unwraps errors, havingpgx.ErrNoRows
unwrap into asql.ErrNoRows
would makeIs
(and as a side-benefit,As
) work for bothpgx
andsql
errors, while still returningpgx.ErrNoRows
. This can be done while keeping the string content and current behavior oferrors.Is(err, pgx.ErrNoRows)
Describe alternatives you've considered
Having my DB implementations wrap the pgx-returned errors with an application-specific equivalent of "no rows" before leaving the DB interface and checking against that works (and is what I'm doing currently), but requires extra boilerplate.
I could also eschew the pgx interface and just use
database/sql
, but I'm usingpgxpool
, and I'm not sure if there's a way to access the native DB interface from a*pgxpool.Pool
.Additional context
None that I can think of.
The text was updated successfully, but these errors were encountered: