canonical / sqlair

Friendly type mapping for SQL databases
Apache License 2.0
17 stars 8 forks source link

Set to zero on `NULL` #80

Closed Aflynn50 closed 1 year ago

Aflynn50 commented 1 year ago

With sql.Rows.Scan, when you are trying to read a NULL from the query results into a Go type, you will get an error (unless the type has nil). This PR changes that behaviour for SQLair. Instead of an error, the value will be set to a zero on finding a Null in the database.

If the type is already a pointer or implements sql.Scanner it is passed straight to Rows.Scan. However, if it not, a pointer to it is passed to Scan and after scanning, if the pointer is nil then the value is zeroed, otherwise it is set.