Skip to content

sqlc.embed that overrides struct field name #3745

Open
@marko995

Description

@marko995

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions