Wrong return type in raw sql
Greetings I have simple aggregations on mysql:
Even if I specify
<number>
the return type is coming back as string when I check with typeof reviewCount
and in other.
Is there a way to typecast raw sql queries, rather than modifying the executed query results or not 🤔Solution:Jump to solution
Kysely doesn't do any data transformations. The underlying driver has full control over that.
Some drivers might not unwrap numeric values of result columns that might exceed javascript's safe number range.
If the driver returns column metadata with the results, you could extend the dialect and automatically unwrap specific result columns by data type.
If not, you can implement a custom plugin that allows per-query transformation of result columns given in a list....
5 Replies
Hey 👋
What dialect are you using?
Hello 🤗 Planetscale dialect
Solution
Kysely doesn't do any data transformations. The underlying driver has full control over that.
Some drivers might not unwrap numeric values of result columns that might exceed javascript's safe number range.
If the driver returns column metadata with the results, you could extend the dialect and automatically unwrap specific result columns by data type.
If not, you can implement a custom plugin that allows per-query transformation of result columns given in a list.
btw, Kysely has built-in aggregate functions.
Wooow thanks a lot for the suggestions Igal, it helped a lot ❤️