Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Have pgx.ErrNoRows wrap sql.ErrNoRows #1931

Open
jessdwitch opened this issue Mar 6, 2024 · 1 comment
Open

Have pgx.ErrNoRows wrap sql.ErrNoRows #1931

jessdwitch opened this issue Mar 6, 2024 · 1 comment

Comments

@jessdwitch
Copy link

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.

@jessdwitch jessdwitch changed the title Have pgx.ErrNoRows nest sql.ErrNoRows Have pgx.ErrNoRows wrap sql.ErrNoRows Mar 6, 2024
@jackc
Copy link
Owner

jackc commented Mar 9, 2024

Seems reasonable. 👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants