Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate const array of possible enum values #2601

Open
gwax opened this issue Aug 9, 2024 · 0 comments
Open

Generate const array of possible enum values #2601

gwax opened this issue Aug 9, 2024 · 0 comments
Labels

Comments

@gwax
Copy link

gwax commented Aug 9, 2024

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I would like to have values matching possible enum values that are synchronized to the database schema for looping or use with zod and similar tools.

Describe the solution you'd like
A clear and concise description of what you want to happen.

for a schema:

export type Database = {
  public: {
    Enums: {
      mytype: "value" | "other"
    }
  }
}

I would like to have generated values:

export const DatabaseValues = {
  public: {
    Enums: {
      mytype: ["value", "other"],
    },
  },
} as const;

this would allow defining zod types to match like:

const mySchema = z.object({
  mytype: z.enum(DatabaseValues.public.Enums.mytype),
});

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

  • manually keeping values in sync with the database and hoping they don't fall out of sync
  • writing custom type checkers to ensure that values match the schema

Additional context
Add any other context or screenshots about the feature request here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants