georgysavva / scany

Library for scanning data from a database into Go structs and more
MIT License
1.23k stars 67 forks source link

question: why scany.ErrNotFound instead of sql.ErrNoRows #106

Closed mxmaxime closed 1 year ago

mxmaxime commented 1 year ago

Hi, First of all, thanks for the project, it looks really great!

I have a question concerning the ErrNotFound. Why did you create one new type/error instead of using the sql.ErrNoRows. I had to wrap the error handling to return the sql.ErrNoRows in order to not break any existing code which is database/sql "compliant".

I might miss something there, I'm curious about this choice. Thanks!

georgysavva commented 1 year ago

Hi! Thanks for asking. The custom ErrNotFound error lives on the dbscan package level because that package doesn't depend on any particular implementation such as database/sql.

Assuming you are using the sqlscan package, it does translate the dbscan.ErrNotFound error to sql.ErrNoRows. The code is here: https://github.com/georgysavva/scany/blob/0203330fd43f46f404de6ce76953e656961989fc/sqlscan/sqlscan.go#L122-L140.

The same is true for the pgxscan package, with the result error type being pgx.ErrNoRows.

I hope this helps. Let me know if you have any other questions.

mxmaxime commented 1 year ago

Thanks for the answer! Crystal clear. I'll use sqlscan then, the code you referenced is basically what I did to wrap dbscan.