Skip to content
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

sqlc.embed that overrides struct field name #3745

Open
marko995 opened this issue Dec 13, 2024 · 0 comments
Open

sqlc.embed that overrides struct field name #3745

marko995 opened this issue Dec 13, 2024 · 0 comments

Comments

@marko995
Copy link

marko995 commented Dec 13, 2024

What do you want to change?

Hey guys,
I can't find something like this in documentation, so I want to ask if it is possible to override the field name in struct using sqlc.embed?

For example, I have a table that contains two foreign keys to same table. When I wrote the query:

SELECT sqlc.embed(g), sqlc.embed(home_team), sqlc.embed(away_team)
FROM game g
LEFT JOIN team home_team ON g.home_team_id = home_team.id
LEFT JOIN team away_team ON g.away_team_id = away_team.id
..............

model looks like this:

type GamesWithTeamsByParamsRow struct {
	Game   Game
	Team   Team
	Team_2 Team
}

Is it possible look like this:

type GamesWithTeamsByParamsRow struct {
	Game   Game
	HomeTeam   Team
	AwayTeam Team
}

I tried using AS home_team and AS away_team, but it doesn't work.

If this feature doesn't exist, may I suggest adding a new argument to sqlc.embed that will tell to generator how to call that field.

What database engines need to be changed?

PostgreSQL, MySQL, SQLite

What programming language backends need to be changed?

Go

@marko995 marko995 added the enhancement New feature or request label Dec 13, 2024
@marko995 marko995 changed the title sqlc.embed that override struct name sqlc.embed that overrides struct field name Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant