You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix!: handle sql/driver.Valuer types properly in slogjson (#219)
Currently, if a field like `sql.NullInt32` has `Valid: False`, `sloghuman` will export it's value as `<nil>`, regardless of it's `String`.
This is because it checks `(driver.Valuer).Value()`.
However, `slogjson` currently sets the value to the json string of the raw struct:
```json
{
"fields": {
"Code": "{Int32:0 Valid:false}",
"ValidCode": "{Int32:12 Valid:true}"
}
}
```
This PR handles this case by first checking if the type implements `sql/driver.Valuer`. If `Valid` is `false` then a JSON `null` value is produced:
```json
{
"fields": {
"Code": null,
"ValidCode": 12
}
}
```
This matches the behaviour of `sloghuman`.
This is technically a breaking change, as these types are now `T | null` instead of `String`, where `T` is the corresponding JSON type of `sql.Null<V>`
0 commit comments