You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This bug has been reported before in #606, but I wanted to bump the issue and provide a work around!
The issue is that with the setup provided, and similar setups, there is an issue with query aliases and type overrides. I'm trying to override the assets.total field, but when aliasing it in the query we can the following struct output.
I went through and output the plugin.Column values while returning the goType in the log output. As you can see, the name for the types in "columns" in the queries is now set as the alias. This means that when checking for an override, we can't find one. I thought for a while about how to solve this problem without changing the architecture, but I think an extra field may need to be added to the plugin.Column struct.
Meanwhile, we can actually work around this problem pretty simply by adding another override to our sqlc.yaml. All I have to do is make my overrides read
This is certainly not elegant or ideal, but it does work. Considering how niche this particular issue appears to be, I don't know if a fix is desperately needed either. I hope this helps anyone running into a similar issue!
CREATEDOMAINuint64ASnumeric(20,0) CHECK(0<= VALUE AND VALUE <=18446744073709551615);
CREATE TABLE
assets (
id bigintPRIMARY KEYCHECK(id >=0),
total uint64 NOT NULL,
decimals intNOT NULLCHECK(decimals >=0AND decimals <=19),
asset_name VARCHAR(32),
unit_name VARCHAR(8),
creator_address VARCHAR(58) NOT NULLCHECK(length(creator_address) =58)
);
SQL queries
-- name: GetAsset :oneSELECT
id AS asset_id,
total AS asset_total,
decimals AS asset_decimals,
asset_name AS asset_name,
unit_name AS asset_unit_name,
creator_address AS creator
FROM assets WHERE id = $1LIMIT1;
Version
1.14.0
What happened?
This bug has been reported before in #606, but I wanted to bump the issue and provide a work around!
The issue is that with the setup provided, and similar setups, there is an issue with query aliases and type overrides. I'm trying to override the assets.total field, but when aliasing it in the query we can the following struct output.
I went through and output the plugin.Column values while returning the goType in the log output. As you can see, the name for the types in "columns" in the queries is now set as the alias. This means that when checking for an override, we can't find one. I thought for a while about how to solve this problem without changing the architecture, but I think an extra field may need to be added to the plugin.Column struct.
Meanwhile, we can actually work around this problem pretty simply by adding another override to our sqlc.yaml. All I have to do is make my overrides read
This is certainly not elegant or ideal, but it does work. Considering how niche this particular issue appears to be, I don't know if a fix is desperately needed either. I hope this helps anyone running into a similar issue!
Relevant log output
Database schema
SQL queries
Configuration
Playground URL
No response
What operating system are you using?
Linux
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
The text was updated successfully, but these errors were encountered: