Open
Description
Version
1.18.0
What happened?
I am running sqlc version 1.18.0
In mysql query, I am expecting dispute_days to to be a go pointer type *int32 and create_dt to be go pointer type *string. However, due to being wrapped in CASE WHEN function and DATE_FORMAT function respectively, the overrides in sqlc.yaml is not being correctly interpreted, therefore create_dt is only coming back as a string, not a *string and dispute_days is coming back as an interface{} when I need it to be an *int32. My resulting details go struct after running sqlc generate comes out like this:
type Details struct {
SkDetailsID int32 `json: "sk_details_id"`
FkDmaName *string `json: "fk_dma_name"`
CreateDt string `json: "create_dt"`
DisputeDays interface{} `json: "dispute_days"`
DisputeEndDate *string `json: "dispute_end_date"`
}
Relevant log output
No response
Database schema
CREATE TABLE details {
sk_details_id int(11) NOT NULL AUTO_INCREMENT,
fk_dma_name varchar(100),
create_dt datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
dispute_days int(11) DEFAULT NULL,
dispute_end_date datetime DEFAULT NULL
}
SQL queries
SELECT
d.details_id,
d.fk_dma_name,
DATE_FORMAT(d.create_dt, '%Y-%m-%d %T') create_dt,
CASE WHEN d.dispute_end_date IS NULL THEN DATEDIFF(NOW(), d.create_dt) ELSE d.dispute_days END dispute_days,
d.dispute_end_date
FROM details d;
Configuration
version: "1"
packages:
- path: "internal/sqlc"
name: "sqlc"
schema: "internal/database/schema/"
queries: "internal/database/queries/"
engine: "mysql"
emit_pointers_for_null_types: true
emit_json_tags: true
overrides:
- db_type: "datetime"
go_type:
type: "string"
pointer: true
nullable: true
- db_type: "int"
go_type:
type: "int32"
pointer: true
nullable: true
- column: "details.dispute_days"
go_type:
type: "int32"
pointer: true
nullable: true
Playground URL
https://play.sqlc.dev/p/37f5fb2be65df3457d87102edf400030d0839cb13f9f109d09bd6e08a0bff22c
What operating system are you using?
macOS
What database engines are you using?
MySQL
What type of code are you generating?
Go