We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
drizzle-orm
0.28.6
drizzle-kit
0.19.13
The typebox schema and types generated for enum arrays is wrong.
Reproduction:
import { pgTable, pgEnum } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-typebox'; export const flags = pgEnum('flags', ['flag-1', 'flag-2', 'flag-3', 'flag-4']); export const test = pgTable('Test', { flags: flags('flags').array().notNull(), }); const insertSchema = createInsertSchema(test); type Insert = typeof insertSchema.static; /* type Insert = { flags: 'flag-1' | 'flag-2' | 'flag-3' | 'flag-4'; }; */ const selectSchema = createSelectSchema(test); type Select = typeof selectSchema.static; /* type Select = { flags: 'flag-1' | 'flag-2' | 'flag-3' | 'flag-4'; }; */
Manual workaround:
import { pgTable, pgEnum } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-typebox'; import { Type } from '@sinclair/typebox'; export const flags = pgEnum('flags', ['flag-1', 'flag-2', 'flag-3', 'flag-4']); export const test = pgTable('Test', { flags: flags('flags').array().notNull(), }); const insertSchema = createInsertSchema(test, { flags: Type.Array( Type.Union([ Type.Literal('flag-1'), Type.Literal('flag-2'), Type.Literal('flag-3'), Type.Literal('flag-4'), ]), ), }); type Insert = typeof insertSchema.static; /* type Insert = { flags: ('flag-1' | 'flag-2' | 'flag-3' | 'flag-4')[]; }; */ const selectSchema = createSelectSchema(test, { flags: Type.Array( Type.Union([ Type.Literal('flag-1'), Type.Literal('flag-2'), Type.Literal('flag-3'), Type.Literal('flag-4'), ]), ), }); type Select = typeof selectSchema.static; /* type Select = { flags: ('flag-1' | 'flag-2' | 'flag-3' | 'flag-4')[]; }; */
Return array, as specified in the drizzle schema, without manually overriding the field.
import { pgTable, pgEnum } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-typebox'; export const flags = pgEnum('flags', ['flag-1', 'flag-2', 'flag-3', 'flag-4']); export const test = pgTable('Test', { flags: flags('flags').array().notNull(), }); const insertSchema = createInsertSchema(test); type Insert = typeof insertSchema.static; /* type Insert = { flags: ('flag-1' | 'flag-2' | 'flag-3' | 'flag-4')[]; }; */ const selectSchema = createSelectSchema(test); type Select = typeof selectSchema.static; /* type Select = { flags: ('flag-1' | 'flag-2' | 'flag-3' | 'flag-4')[]; }; */
No response
The text was updated successfully, but these errors were encountered:
Having this issue as well
Sorry, something went wrong.
Hi
I've looked into this and found a solution. I'll be sending a PR shortly.
No branches or pull requests
What version of
drizzle-orm
are you using?0.28.6
What version of
drizzle-kit
are you using?0.19.13
Describe the Bug
The typebox schema and types generated for enum arrays is wrong.
Reproduction:
Manual workaround:
Expected behavior
Return array, as specified in the drizzle schema, without manually overriding the field.
Environment & setup
No response
The text was updated successfully, but these errors were encountered: