Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Custom Go types for query parameters #607

Answered by kyleconroy
tv42 asked this question in Issue Triage
Discussion options

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 table.column, identity. Maybe the mapping has to be in the query metadata, like -- name: and such.

You must be logged in to vote

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.

Replies: 1 comment

Comment options

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.

You must be logged in to vote
0 replies
Answer selected by kyleconroy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #607 on August 23, 2020 19:56.

AltStyle によって変換されたページ (->オリジナル) /