Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
database/sql: support custom input types / output types, custom conversion #18417
This is a master tracking issues for various requests to support custom parameter types and custom scan types. This includes may geometry types, slices, structured fields. This issue also tracks issues related to conversion of one type into another type.
I'd like to flush out a proposal here before go1.8 is released so it can be implemented smoothly in the go1.9 window. I would expect few public API additions. There might be a new interface or two in
There's a ref to rana/ora#145 about Oracle (and friends) Stored Procedures OUT params support,
Just for inspiration, here's an example how JDBC statement support these.
Whether statements support this or multi-value types result can also work,
@asaf I'd also like to enable OUT params. I would see it being implemented in the public
Regarding #18415, allowing custom converters would be one option.
My main problem with the current situation is that the driver has an OCINum, that may or may not be represented as an int32 or int64 or float6r, but always can be a string.
If sql could provide the type what the user is Scanning into, then the driver could make a more informative decision about the conversion.
Now it uses float64 as the least wrong.
The same is with a LOB: if the user scans into an io.Reader, then the driver don't have to slurp all the content into memory.
I'm one of the authors of SQLBoiler (https://github.com/vattle/sqlboiler), we're currently using our own extended types packages to handle this, but it'd be very nice if it was part of the stdlib. What we currently use:
This allows us to support all types as nullable (not only the ones currently in stdlib), hstore, 1 dimensional Postgres arrays and JSON. Would be very cool to see these added to the stdlib so we could drop support for these ugly dependencies we've had to craft :-).
These are the mappings we currently use if you care to know/if it's of any help or relevance:
Previously all arguments were passed through driver.IsValid. This checked arguments against a few fundamental go types and prevented others from being passed in as arguments. The new interface driver.NamedValueChecker may be implemented by both driver.Stmt and driver.Conn. This allows this new interface to completely supersede the driver.ColumnConverter interface as it can be used for checking arguments known to a prepared statement and arbitrary query arguments. The NamedValueChecker may be skipped with driver.ErrSkip after all special cases are exhausted to use the default argument converter. In addition if driver.ErrRemoveArgument is returned the argument will not be passed to the query at all, useful for passing in driver specific per-query options. Add a canonical Out argument wrapper to be passed to OUTPUT parameters. This will unify checks that need to be written in the NameValueChecker. The statement number check is also moved to the argument converter so the NamedValueChecker may remove arguments passed to the query. Fixes #13567 Fixes #18079 Updates #18417 Updates #17834 Updates #16235 Updates #13067 Updates #19797 Change-Id: I89088bd9cca4596a48bba37bfd20d987453ef237 Reviewed-on: https://go-review.googlesource.com/38533 Reviewed-by: Brad Fitzpatrick <email@example.com> Run-TryBot: Brad Fitzpatrick <firstname.lastname@example.org> TryBot-Result: Gobot Gobot <email@example.com>