-
Notifications
You must be signed in to change notification settings - Fork 902
Closed
Labels
📚 mysql💻 linux🔧 golangbugSomething isn't workingSomething isn't workingtriageNew issues that hasn't been reviewedNew issues that hasn't been reviewed
Description
Version
1.10.0
What happened?
Generated code causes an error when it tried to scan a row from a table with a nullable enum column.
Relevant generated code:
type Resource struct {
ID int32 `json:"id"`
KeyState ResourceKeyState `json:"key_state"`
}
type ResourceKeyState string
const (
ResourceKeyStateNOTYETACTIVE ResourceKeyState = "NOT_YET_ACTIVE"
ResourceKeyStateACTIVE ResourceKeyState = "ACTIVE"
ResourceKeyStateINACTIVE ResourceKeyState = "INACTIVE"
ResourceKeyStateDELETIONSCHEDULED ResourceKeyState = "DELETION_SCHEDULED"
)
func (e *ResourceKeyState) Scan(src interface{}) error {
switch s := src.(type) {
case []byte:
*e = ResourceKeyState(s)
case string:
*e = ResourceKeyState(s)
default:
return fmt.Errorf("unsupported scan type for ResourceKeyState: %T", src)
}
return nil
}
Expected:
Generated code should recognize that the column can have null values, and scan values from it accordingly.
Relevant log output
{"log.level":"ERROR","@timestamp":"2022-06-01T03:58:17.096Z","log.origin":{"file.name":"<REDACTED>.go","file.line":179},"message":"sql: Scan error on column index 7, name \"key_state\": unsupported scan type for ResourceKeyState: <nil> (rest of log message REDACTED)"}
Database schema
CREATE TABLE `resource` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`key_state` enum('NOT_YET_ACTIVE','ACTIVE','INACTIVE','DELETION_SCHEDULED') DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
SQL queries
/* name: GetResourceById :one */
SELECT * FROM resource
WHERE id = ? ;
Configuration
{
"version": "2",
"sql": [
{
"schema": "sqlc/<REDACTED>.sql",
"queries": "sqlc/<REDACTED>.sqlc.sql",
"engine": "mysql",
"gen": {
"go": {
"emit_json_tags": true,
"package": "sqlcgen",
"out": "components/sqlc"
}
}
}
]
}
Playground URL
No response
What operating system are you using?
Linux, macOS
What database engines are you using?
MySQL
What type of code are you generating?
Go
akares
Metadata
Metadata
Assignees
Labels
📚 mysql💻 linux🔧 golangbugSomething isn't workingSomething isn't workingtriageNew issues that hasn't been reviewedNew issues that hasn't been reviewed