Custom Go types for query parameters #607
-
I like using Go types to keep my FooID's separate from by BarID's, even if both are uint64. https://github.com/kyleconroy/sqlc#per-column-type-overrides lets me do that neatly for the result rows coming from the database. But that doesn't help with parameters: both my foos and bars are just int64, which means when I call the generated methods I need to manually convert, and I have to remember when to use int64, when int32, etc. I'd like to see some mechanism to set Go types for the bind parameters too. Obviously they're not as neatly connected to a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There are a few different solutions we could employ to solve this issue. The first is applying type overrides to parameters. If we know that a parameter directly refers to The second solution may lie in #434. If you created a domain for FooID and BarID, you would only need to override a single type. For now, I've created #671 to track the first solution. |
Beta Was this translation helpful? Give feedback.
There are a few different solutions we could employ to solve this issue.
The first is applying type overrides to parameters. If we know that a parameter directly refers to
table.column
, sqlc should apply the type override to that parameter. This becomes more complicated if a table has a foreign key to a column. Currently you need to add a separate type override for those columns. I don't imagine changing that behavior right now.The second solution may lie in #434. If you created a domain for FooID and BarID, you would only need to override a single type.
For now, I've created #671 to track the first solution.