-
Notifications
You must be signed in to change notification settings - Fork 863
sqlc.embed doesn't follow alias naming for table #2686
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
Comments
I also opened a duplicate of this as an enhancement: #2719 The idea suggested is slightly different though (eg: put this behind a configuration option as to not make it a breaking change). Also:
|
Reviewing my suggestion PR, I think it can be set behind a configuration option. I just need to look how to access it in this part of the code. |
I think this might be worth a breaking change. As discussed in #2718, using these aliases doesn't work right now. sqlc adopts the alias name of a column as the name of the field, doing that here. @sapk You don't need to update your PR just yet, as I need to verify that this change won't be too large of a breaking change. |
Maybe as a safety we could set the option as new logic by default and if someone trigger a corner-cases it can revert to old one if needed. In case of no issue reported, we could remove the config flag to keep only the new logic in later version. |
You can do this on pggen with -- name: ListUserRelation :many
SELECT
owner,
consumer
FROM
user_links
INNER JOIN users AS owner ON owner.id = user_links.owner_id
INNER JOIN users AS consumer ON consumer.id = user_links.consumer_id; This query executes as-is on Postgres, returning 2 columns of the composite type for the |
I see OP is using MySQL so composite types are not an option there. For Postgres users, it would be useful to have a way to scan a composite type of the table to the same struct that |
Are you using |
@andrewmbenton @sapk as a mysql user mysql, I'm looking forward to this solution. Will the current PR go ahead as designed? |
Version
1.20.0
What happened?
This prevent to do multiple join with the same table. Like a table making between multiple entries like linking users to users.
With the provided example the resulting struct would look like:
I would expect it to look like:
I could work on a fix. I just first want to make sure that it would be ok to switch to the format I would expect.
Relevant log output
No response
Database schema
SQL queries
Configuration
Playground URL
https://play.sqlc.dev/p/f81ff911dc5e18f6398998262c44b25169a2b4685d81c9dfc9669d962f3e26a5
What operating system are you using?
Linux
What database engines are you using?
MySQL
What type of code are you generating?
Go
The text was updated successfully, but these errors were encountered: