[BUG]: drizzle-zod's createInsertSchema() can't handle column of type `vector`
Problem
What version of `drizzle-orm` are you using? 0.31.0 What version of `drizzle-kit` are you using? 0.22.1 Describe the Bug One of my columns is of type `vector` (from the `pgvector` extension). I use `createInsertSchema()` from the `drizzle-zod` package to create a Zod schema for that table. When navigating to the page where that Zod schema is used, I'm getting the following error: `Error Cannot use 'in' operator to search for 'enumValues' in undefined` When I remove the `vector` column, everything works fine. I'm not really sure why the error talks about `enumValues` at all..but I figured it must have something to do with the `vector` column. [code block] schema: [code block] Expected behavior Error should not happen. Environment & setup I'm using "drizzle-zod": "^0.5.1" Full Error stack: [code block]
Error Output
error: `Error Cannot use 'in' operator to search for 'enumValues' in undefined`
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix drizzle-zod createInsertSchema() to Support vector Column Type
The error occurs because the `createInsertSchema()` function in drizzle-zod does not have a defined handling mechanism for the `vector` type from the pgvector extension. This results in an undefined value being passed where an object is expected, leading to the error about 'enumValues'.
Awaiting Verification
Be the first to verify this fix
- 1
Update drizzle-zod to Support vector Type
Modify the drizzle-zod library to include a handler for the `vector` type. This involves adding a case in the schema creation logic that correctly processes the vector type and defines its structure.
typescriptfunction createInsertSchema(table) { // Existing code... if (table.columnType === 'vector') { return z.array(z.number()).length(table.vectorLength); } // Existing code... } - 2
Test the Updated Schema
Create a test case that includes a `vector` column in the schema and ensure that the `createInsertSchema()` function executes without errors. Validate that the generated Zod schema correctly reflects the expected structure.
typescriptconst schema = createInsertSchema({ columns: { myVector: { type: 'vector', vectorLength: 3 } } }); console.log(schema); // Should not throw an error - 3
Update Documentation
Update the documentation for drizzle-zod to include examples of how to use the `vector` type in schemas. This will help future users understand how to implement this feature correctly.
markdown// Example usage in documentation: const vectorSchema = createInsertSchema({ columns: { myVector: { type: 'vector', vectorLength: 3 } } }); - 4
Publish Updated Package
After testing, publish the updated drizzle-zod package to ensure that all users can access the fix. Make sure to increment the version number according to semantic versioning rules.
bashnpm version patch npm publish
Validation
Confirm that the error no longer occurs when using the `vector` column in the Zod schema. Additionally, run all existing tests to ensure no other functionalities are broken.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep