-
Notifications
You must be signed in to change notification settings - Fork 818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support nil pointers to value implementing driver.Valuer #339
Comments
I'm also not sure if pgx checks properly if a type implements driver.Valuer with a pointer receiver. When I try, I get an error like this:
Instead of calling Value() on the pointer receiver, it seems to try to coerce the pointer into Numeric. |
I used the same fix as was done for the standard lib. It now incurs a reflect operation for each driver.Valuer argument, but there doesn't seem to be any way around it. |
Do you have any insight into the second comment I made on this issue? Just to clarify what I'm doing, is I'm trying to avoid having to create a wrapper type to check if it's null. type Decimal struct {...}
func (z *Decimal) Value() (driver.Value, error) {
if z == nil {
return nil, nil
}
return z.String(), nil
} Let me know if this endeavor is inane and I should just use a NullDecimal wrapper type. |
I don't think you should need a wrapper. I have a working test in the test suite with a |
The test for issue jackc#339 actually can work for any custom type that implement driver.Valuer, we did not need to import another package just for testing it, which minimize the package dependencies. While at it, remove invalid instruction to "go get" the package go-version in README.
For example, you can't do something like this:
Relevant discussion with the Go stdlib is here: golang/go#8415
Commit fixing this in Go stdlib is here: golang/go@0ce1d79
The text was updated successfully, but these errors were encountered: