[Pg] Fix: Postgis `geometry` query select fails when using `with`
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.
@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 😊.
yes, let me take a look
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!
@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.
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:
- Adding the above to
./patches/[email protected] - Adding the following to your
package.json
"pnpm": {
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
}
}
- Run
pnpm install
Not sure if sharing patches like this works - if not:
- clone
drizzle-orm - Make the changes to the source code (from the commits here)
- Go to your app, run
pnpm patch drizzle-orm@<VERSION>(this will give you a path - keep this for step 5) - Build
drizzle-orm - Copy the files generated into
./drizzle-orm/distinto the path you got earlier - 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.
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.
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.
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!
Same here, would love to see a fix rolled out 🙏🏻
Hi @AndriiSherman, do you have an estimation when this will be included in a release?