Closed
Description
Version
1.19.1
What happened?
The code associated with the enum field is generated even if the table is dropped after define this field.
Relevant log output
type StreamSessionState string
const (
StreamSessionStateACTIVATING StreamSessionState = "ACTIVATING"
StreamSessionStateACTIVE StreamSessionState = "ACTIVE"
StreamSessionStateCONNECTED StreamSessionState = "CONNECTED"
StreamSessionStatePENDINGCLIENTRECONNECTION StreamSessionState = "PENDING_CLIENT_RECONNECTION"
StreamSessionStateTERMINATED StreamSessionState = "TERMINATED"
StreamSessionStateERROR StreamSessionState = "ERROR"
)
func (e *StreamSessionState) Scan(src interface{}) error {
switch s := src.(type) {
case []byte:
*e = StreamSessionState(s)
case string:
*e = StreamSessionState(s)
default:
return fmt.Errorf("unsupported scan type for StreamSessionState: %T", src)
}
return nil
}
type NullStreamSessionState struct {
StreamSessionState StreamSessionState
Valid bool // Valid is true if StreamSessionState is not NULL
}
// Scan implements the Scanner interface.
func (ns *NullStreamSessionState) Scan(value interface{}) error {
if value == nil {
ns.StreamSessionState, ns.Valid = "", false
return nil
}
ns.Valid = true
return ns.StreamSessionState.Scan(value)
}
// Value implements the driver Valuer interface.
func (ns NullStreamSessionState) Value() (driver.Value, error) {
if !ns.Valid {
return nil, nil
}
return string(ns.StreamSessionState), nil
}
Database schema
CREATE TABLE `stream_session` (
`id` int NOT NULL AUTO_INCREMENT,
`external_id` varchar(256) DEFAULT NULL,
`stream_group_id` int NOT NULL,
`state` enum('ACTIVATING','ACTIVE','CONNECTED','PENDING_CLIENT_RECONNECTION','TERMINATED','ERROR') NOT NULL,
PRIMARY KEY (`id`),
KEY `stream_group_id` (`stream_group_id`),
CONSTRAINT `stream_session_ibfk_1` FOREIGN KEY (`stream_group_id`) REFERENCES `stream_group` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
DROP TABLE stream_session;
SQL queries
No response
Configuration
version: "2"
sql:
- schema: "db/schema/DDL"
queries: "db/query"
engine: "mysql"
gen:
go:
package: "db"
out: "db/sqlc"
emit_json_tags: true
emit_interface: true
emit_empty_slices: true
emit_exact_table_names: true
Playground URL
No response
What operating system are you using?
macOS
What database engines are you using?
MySQL
What type of code are you generating?
Go