Skip to content

Support enums in gentool #1373

@diogox

Description

@diogox

Describe the feature

On Postgres, we can define:

CREATE TYPE fruit AS ENUM ('orange', 'pineapple', 'peach');

Other tools that generate Go code from DB schemas, such as sqlboiler, will generate the following:

type Fruit string

// Enum values for Fruit
const (
	FruitOrange       Fruit = "orange"
	FruitPineapple    Fruit = "pineapple"
	FruitPeach        Fruit = "peach"
)

I was wondering if we can have the same feature in gentool.

Motivation

Without this code generation, we run the risk of checking against the wrong string values (especially when adding/removing them from the schema).

Having this generated, would allow us to check confidently against the schema like so:

if result.Fruit == model.FruitOrange {
  // TODO
}

Related Issues

#1033 - contrary to this ticket, I'd like the gentool to generate the constants for me based on the schema it already has. Not map them to manually written ones.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions