Asserting type of .countAll() (MySQL)
I've noticed that the return type from the result of aggregation functions like
countAll()
and sum()
are string | number | bigint
.
I assume this is in-case the number returned is too large to be stored in a JS "number." In my case, it appears to be being returned as strings
. Is it possible to assert it as a number
so that I don't need to wrap every query in a parseInt(result as string, 10)
?Solution:Jump to solution
nvm got it
```ts
await db
.selectFrom("player_stats")
.where("last_active", ">", dateThreshold)...
3 Replies
Followup question, why is
string
a possibility when we can express larger numbers in bigint
?Solution
nvm got it
Hey 👋
Kysely's API is dialect and underlying driver agnostic, by design. It doesn't do any data transformation, leaving everything to the underlying driver.
Also note, some aggregate functions are nullable in some extreme edge cases. You can provide a nullable generic type too.