-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
database/sql: allow drivers to support additional Value types #13567
Comments
/cc @bradfitz |
I'm thinking maybe create a new interface that drivers can implement. If they do, use it, if not, don't. Should ensure compatibility. |
Databases can support non-standard result types. Common ones that are found include arrays, JSON, XML, table valued types, IP addresses, and GIS types. For scanning custom result types I propose the following changes are made:
I think the above should allow returning any database supported type. Using any type as input parameters will be another issue. |
This would also allow drivers to truly support |
CL https://golang.org/cl/38533 mentions this issue. |
It'd be useful if drivers could augment the list of data types supported by database/sql/convert.go. The ability to implement driver.Valuer and sql.Scanner for one's own structs is great, but there are core types I'd like to be able to use, as well. For example, PostgreSQL supports array types. I'd love to be able to convert between slices and SQL arrays. It makes sense that database/sql would not support this, but if there was an interface for the pg or pgx drivers to add it for core types, it would be super useful. Perhaps Driver could have methods for this kind of conversion? Maybe something like:
Then the drivers could be updated to, say, convert between
[]string
andTEXT[]
.The text was updated successfully, but these errors were encountered: