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
The naming here isn't very helpful. Do you have any suggestions on how this can be improved? Either by using a different kind of query (that allows updating multiple fields, each one optional) or by somehow annotating things such that the params struct uses more helpful naming?
Agreed. It also appears there's something strange going on with the names. There's not reason the second parameter should be Column2_2, it should just be Column2. That said, even the "correct" names are unhelpful.
Do you have any suggestions on how this can be improved?
I think I do. We already do inference of parameter names. It's how the query UPDATE foo SET bar = $1 gives you a parameter named Bar, not Column_1. It should be possible to recognize the pattern you're using and generate a struct that looks like this:
type UpdateFooParams struct {
SetBar bool `json:"set_bar"`
Bar bar_type `json:"bar"`
}
Would that be good enough for your needs?
by somehow annotating things such that the params struct uses more helpful naming?
We've talked about overriding parameters names in #71
Activity
kyleconroy commentedon Dec 17, 2019
Agreed. It also appears there's something strange going on with the names. There's not reason the second parameter should be
Column2_2, it should just beColumn2. That said, even the "correct" names are unhelpful.I think I do. We already do inference of parameter names. It's how the query
UPDATE foo SET bar = $1gives you a parameter namedBar, notColumn_1. It should be possible to recognize the pattern you're using and generate a struct that looks like this:Would that be good enough for your needs?
We've talked about overriding parameters names in #71
joshuarubin commentedon Dec 17, 2019
Yeah, that's exactly what I'd like. That can be done already?
kyleconroy commentedon Dec 17, 2019
I wish because then I wouldn't have to write it! Sadly it needs to be implemented. In the meantime, you're stuck with terrible parameter names :(
kyleconroy commentedon Feb 10, 2020
@joshuarubin I just landed support for named parameters. Your original query can be rewritten like so:
You can also use the
@shorthand: