georgysavva / scany

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

scan when timestamp not initialised #91

Closed p4r4g closed 1 year ago

p4r4g commented 2 years ago

I maintain application state using a structure, which is mapped to sql columns. One of the columns is of type json and hold timestamp info.

If I write the structure to db (which is partially initialized), this results the fill_timestamp":"0001-01-01T00:00:00Z". when scany tries to parse it, it throws error - : can't scan into dest[10]: unknown time format.

I am okay for the error, but it actually gives up everything else and returns null data. Any solution on how to ignore the error and fetch other data?

georgysavva commented 2 years ago

Hi! It would be undesirable to partially return the data despite the parsing errors.

Instead, you shouldn't save timestamps in an invalid format in the database in the first place. Maybe it's worth adapting NULLable fields for timestamp fields that might be empty?

georgysavva commented 1 year ago

Closing due to inactivity. Feel free to reopen.