georgysavva / scany

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

Scan to struct even if it does not contain all columns #80

Closed asgaru84 closed 2 years ago

asgaru84 commented 2 years ago

Is your feature request related to a problem? Please describe. Problem is in no corresponding field found error. Columns that not yet present in struct are OK, because migrations come first and code comes second, crash between two steps is unacceptable

Describe the solution you'd like I want option to skip columns that don't have corresponding fields in destination struct

georgysavva commented 2 years ago

Hello! The intention here is to only select fields that you actually need. So no SELECT *. This way even if you add a new column via DB migration and the code stays the same it won't crash. Besides that I agree, it makes sense to have such an option. There is an open issue about this: https://github.com/georgysavva/scany/issues/72 We outline possible solutions there. If you are interested, you are welcome to shoot a PR!