Closed
Description
What do you want to change?
The codegen for enums generates a list of constants containing valid values:
type EnumType string
const (
EnumTypeA EnumType = "A"
EnumTypeB EnumType = "B"
)
When writing developer tools, it can be helpful to convert from a string value to an enum type. However, there is no exhaustive list of valid enum values, so we have to wait until a query fails to discover that an invalid enum value has been provided.
I'd like the codegen to also emit something like:
func (e EnumType) Valid() bool {
switch e {
case EnumTypeA, EnumTypeB:
return true
default:
return false
}
}
Then I can convert from string to enum type and check valid early on.
I know that this applies to PostgreSQL and Go. I'm not sure about MySQL and the other languages.
What database engines need to be changed?
PostgreSQL
What programming language backends need to be changed?
Go