how to decode a point to `{x: number, y: number}` when selected inside `jsonBuildObject`?
when i select a column of type point the basic way i get it decoded to
{x: number, y: number}
, but when i wrap it in jsonBuildObject
i get it as the raw string.
example:
Solution:Jump to solution
The only way to detect those columns inside JSON is regex or similar. There's no type info. In JSON, that's just a string.
5 Replies
i fail to find the source code for where the point decoding is done in the basic select case
Kysely doesn't decode anything. It never touches the output in any way whatsoever. It's the underlying driver that does the conversions. In this case it's converting the point to JSON and for some reason that's what it does.
You're using postgres? Then it's
pg
that's responsible for the conversions.
But in this particular case the conversion is already done in the DB since it's the DB that converts the column into JSON.
You could use something like this
Point
being something like {x: number, y: number}
or whatever you've typed your points to be.
https://kysely.dev/docs/recipes/data-typesah ok, thanks! in my case the point column is nullable, making it more complicated i guess 🤔 if i were to do it in js-land instead, is a plugin with
transformResult
a reasonable approach?Solution
The only way to detect those columns inside JSON is regex or similar. There's no type info. In JSON, that's just a string.
But if that's ok, then a plugin is a good solution.