georgysavva / scany

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

Add special type for scanning of unused columns (V1) #132

Closed br3w0r closed 6 months ago

br3w0r commented 6 months ago

The problem: at my job when we worked with custom enums there was a problem when a new custom enum wasn't yet added to a struct for scanning. It leaded to an error when SELECT * FROM ... was used:

scany: scan row into struct fields: can't scan into dest[<idx>]: unknown oid <oid> cannot be scanned into *interface {}

This problem occurs because the interface{} type obviously doesn't implement the sql.Scanner interface. So, I added a new type that does the job and replaced the interface{} that was used for scanning of columns which wouldn't be used.

georgysavva commented 6 months ago

Hi, thank you for this catch. Can I ask you to also add a test for this use case please?

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 82.63%. Comparing base (5c09502) to head (2b8f25c).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## v1 #132 +/- ## ========================================== - Coverage 82.81% 82.63% -0.18% ========================================== Files 5 5 Lines 512 432 -80 ========================================== - Hits 424 357 -67 + Misses 73 60 -13 Partials 15 15 ``` | [Flag](https://app.codecov.io/gh/georgysavva/scany/pull/132/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Georgy+Savva) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/georgysavva/scany/pull/132/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Georgy+Savva) | `82.63% <100.00%> (-0.18%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Georgy+Savva#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

br3w0r commented 6 months ago

@georgysavva done!

georgysavva commented 6 months ago

@br3w0r, thank you for your contribution. I will go ahead and release a new version with this fix.