-
Notifications
You must be signed in to change notification settings - Fork 808
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
Vote for New Feature: generate Scan (as specified by sql.Scanner) and driver.Valuer (as specified by driver.Valuer) #108
Comments
I am not really a sql user, could you please explain how this would work in a little more detail? |
This would be awesome. @awalterschulze Scanners can handle nested structures, but it does get a bit difficult, you end up calling the Scanner method of the nested type on some bytes. However, even without supporting that, this would be quite valuable. Also, because we know the schema ahead of time, it should be possible to do Scanning without reflection, which would be even better. |
Maybe someone could give me an example of what the generated code would look like for an example structure? |
Apologies for being MIA despite my initial ask. Providing examples is on my TODO list, but swamped right now! |
@awalterschulze if I understand this correctly, the only feasible implementation of Valuer would be a straight delegation to |
@ecnahc515 you cannot implement |
@tamird Would that support |
I don't see why not. The hardest part of all this will be adding tests, since there's no SQL anything in gogoproto right now. |
Is this still a thing you want? |
I would potentially like to revisit this. Although, I am not in need of complex proto message scan/value support for nesting -> but simply the wrappers defined here. As an example, adding the following to wrappers.pb.go enables the use of a message with a StringValue to be read directly with a SQL call : func (s *StringValue) Scan(value interface{}) error {
if value == nil {
s.Reset()
return nil
}
if bv, err := driver.String.ConvertValue(value); err == nil {
if v, ok := bv.(string); ok {
*s = StringValue{v}
return nil
}
}
return errors.New("failed to scan StringValue")
} Without this patch you get the following type of errors:
Right now I have resolved this by forking the repo and manually adding the Scan and Value methods I need. Happy to create a PR, however, I realize that those files are actually generated and adding support for this to the generator would be the potentially proper solution. If you can point me in the right direction I can dig into that. |
I would recommend building a plugin and then a vanity binary. |
https://github.com/travisjeffery/proto-go-sql - generator I wrote that'll implement sql.Scanner and driver.Valuer |
Nice 😁 could we add your project to the user list in gogoprotobuf?
…On Tue, 27 Mar 2018, 20:00 Travis Jeffery, ***@***.***> wrote:
https://github.com/travisjeffery/proto-go-sql - generator I wrote that'll
implement sql.Scanner and driver.Valuer
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#108 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABvsLbRONEZx-Nv61G2Rq4AvP6FO8ms2ks5tin5FgaJpZM4GDSqk>
.
|
To store protos in a db (as blobs), it would be great to have an extension generating:
The text was updated successfully, but these errors were encountered: