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]: Postgis `geometry` query select fails when using `with` #2526

Open BryanAbate opened 1 week ago

BryanAbate commented 1 week 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

If we have two tables like:

const locations = pgTable('locations', {
  id: serial('id').primaryKey(),
  geoLongitudeLatitude: geometry('geo_longitude_latitude', { type: 'point', mode: 'xy', srid: 4326 }),
})

const tests = pgTable('tests', {
  id: serial('id').primaryKey(),
  locationId: integer('location_id')
    .references(() => locations.id)
    .notNull()
})

relations(tests, ({ one }) => ({
  location: one(locations, {
    fields: [tests.locationId],
    references: [locations.id],
}),

It works fine to select locations by themselves like client.query.locations.findFirst(...) but if we do a join and try a query like:

client.query.tests.findFirst(
  with: {
    location: true
  }
)

Then it fails with the following error:

RangeError: Offset is outside the bounds of the DataView
    at DataView.getUint32 (<anonymous>)
    at parseEWKB

Expected behavior

No response

Environment & setup

No response