drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[Pg] Fix: Postgis `geometry` query select fails when using `with`

Open mauriciabad opened this issue 1 year ago • 9 comments

Fixes https://github.com/drizzle-team/drizzle-orm/issues/2526

Thoughts after fixing the issue

I don't understand why, but sometimes mapFromDriverValue in PgGeometry or PgGeometryObject recieves an object with the data already parsed, and some other times it recieves a string.

So a quick fix is to check when the type is not a string and parse it correctly.

Further investigation to understand why the type changes would be useful.
Because the parseEWKB function is super hard to understand and maybe we can reuse the code that is already parsing the geometry somewhere to get rid of parseEWKB.
Moreover, considering that there's a type property, the function that is parsing the geometry probably works for all geometry types, allowing the creation of a truly generic geometry column type to give wider PostGIS support.

mauriciabad avatar Aug 09 '24 19:08 mauriciabad

@AndriiSherman Can this be included in the next release? It is a blocker for my project (and this one too https://github.com/drizzle-team/drizzle-orm/pull/2774). Thanks, and sorry for tagging 😊.

mauriciabad avatar Aug 14 '24 10:08 mauriciabad

yes, let me take a look

AndriiSherman avatar Aug 14 '24 10:08 AndriiSherman

Anything I can do to lend a hand here? This is blocking for me and I'd love to help get it over the line!

limegorilla avatar Sep 24 '24 12:09 limegorilla

@AndriiSherman any chance this can be approved? We're currently a lot of code around this bug in order to fetch geometries. If I can help with anything to get it released please let me know.

oscar-corredor avatar Oct 10 '24 14:10 oscar-corredor

any chance this can be approved? We're currently a lot of code around this bug in order to fetch geometries. If I can help with anything to get it released please let me know.

@oscar-corredor if you need to get this working asap you can patch drizzle-orm in the meantime.

https://gist.github.com/limegorilla/fc3422da09dea332d9c4bb0ffef61324

That's mine - you should be able to add that to your project by:

  1. Adding the above to ./patches/[email protected]
  2. Adding the following to your package.json
"pnpm": {
    "patchedDependencies": {
      "[email protected]": "patches/[email protected]"
    }
  }
  1. Run pnpm install

Not sure if sharing patches like this works - if not:

  1. clone drizzle-orm
  2. Make the changes to the source code (from the commits here)
  3. Go to your app, run pnpm patch drizzle-orm@<VERSION> (this will give you a path - keep this for step 5)
  4. Build drizzle-orm
  5. Copy the files generated into ./drizzle-orm/dist into the path you got earlier
  6. run pnpm patch-commit

If you're using another pkgmgr than pnpm it should be the same afaik. Only worked out how to patch things because of this.

limegorilla avatar Oct 10 '24 16:10 limegorilla

I had this issue, resolved it with querying location like this:

    extras: {
      x: sql<number>`ST_X(${table.location})`.as("x"),
      y: sql<number>`ST_Y(${table.location})`.as("y"),
    },

It's not perfect, but it lets me use findMany and handle geometry type without issues.

FNDEVVE avatar Oct 12 '24 10:10 FNDEVVE

Is there a deadline or plan to approve this pull request? It's been blocked since October, and many developers including me are facing this issue.

david-bermejo avatar Jan 12 '25 12:01 david-bermejo

Bumping this.

It's a really annoying blocking item that looks like could be fixed by just merging this PR - it's working on my end, would be great to have an approved fix!

busybox11 avatar Feb 26 '25 23:02 busybox11

Same here, would love to see a fix rolled out 🙏🏻

chanmathew avatar Feb 27 '25 00:02 chanmathew

Hi @AndriiSherman, do you have an estimation when this will be included in a release?

Johannes-Krabbe avatar May 09 '25 13:05 Johannes-Krabbe