drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
21.44k stars 484 forks source link

[BUG]: `drizzle-typebox` fails to map geometry column to type-box schema #2516

Open iabdousd opened 2 weeks ago

iabdousd commented 2 weeks ago

What version of drizzle-orm are you using?

0.31.2

What version of drizzle-kit are you using?

0.22.6

Describe the Bug

Adding a geometry column in a pgTable with tuple mode causes the issue.

Example code:

import { geometry, pgTable, text } from "drizzle-orm/pg-core";
import { createInsertSchema } from "drizzle-typebox";

export const restaurants = pgTable("restaurants", {
  name: text("name"),
  location: geometry("location", { type: "point", mode: "tuple" }),
});

export const restaurantsInsertSchema = createInsertSchema(restaurants);

The outcome:

15 | };
16 | let d = function(t) {
17 |   let f;
18 |   if (function(e) {
19 | 
20 |     return ("enumValues" in e) && Array.isArray(e.enumValues) && e.enumValues.length > 0;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ^
TypeError: e is not an Object. (evaluating '"enumValues" in e')
      at /Users/abdulrahman/Desktop/SoftwareSavants/Products/Khairaty/khairaty-api/api/node_modules/drizzle-typebox/index.mjs:1:1161
      at d (/Users/abdulrahman/Desktop/SoftwareSavants/Products/Khairaty/khairaty-api/api/node_modules/drizzle-typebox/index.mjs:1:1232)
      at d (/Users/abdulrahman/Desktop/SoftwareSavants/Products/Khairaty/khairaty-api/api/node_modules/drizzle-typebox/index.mjs:1:1425)
      at /Users/abdulrahman/Desktop/SoftwareSavants/Products/Khairaty/khairaty-api/api/node_modules/drizzle-typebox/index.mjs:1:559
      at map (:1:20)
      at p (/Users/abdulrahman/Desktop/SoftwareSavants/Products/Khairaty/khairaty-api/api/node_modules/drizzle-typebox/index.mjs:1:533)
      at /Users/abdulrahman/Desktop/SoftwareSavants/Products/Khairaty/khairaty-api/api/src/modules/driver/driver.schema.ts:32:39

I've looked into the drizzle-typebox code and it seems like this line is causing the issue: https://github.com/drizzle-team/drizzle-orm/blob/4ecfe1fca3ec0bc8fdec02b6751e030b8832fb41/drizzle-typebox/src/index.ts#L284

Expected behavior

The app compiles successfully

Environment & setup

Database: postgresql

matthiasbayer commented 1 week ago

This might be a duplicate of https://github.com/drizzle-team/drizzle-orm/issues/2424 (or closely related)