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:
nvm got it ```ts await db .selectFrom("player_stats") .where("last_active", ">", dateThreshold)...
O
ohmi336d ago
Followup question, why is string a possibility when we can express larger numbers in bigint?
Solution
O
ohmi336d ago
nvm got it
await db
.selectFrom("player_stats")
.where("last_active", ">", dateThreshold)
.select((eb) => eb.fn.countAll<number>().as("count"))
.executeTakeFirstOrThrow()
await db
.selectFrom("player_stats")
.where("last_active", ">", dateThreshold)
.select((eb) => eb.fn.countAll<number>().as("count"))
.executeTakeFirstOrThrow()
I
Igal336d ago
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.
Want results from more Discord servers?
Add your server
More Posts
Coalesce return empty arrayHey is there a way to return an empty array rather than `null` when an array column is empty? I alrkysely-codegen for multiple databasesI have two MySQL 'databases' within the same instance. From the documentation, it doesn't look like Using MySQL functions in SELECT statementHi! Just trying to migrate over from Knex. Skimmed over the documentation but still unsure of how tExtract OrderBy TS KeysHey I have the following query ```ts const getBaseQuery = ({ offset, pageSize, slug }: GetBaseQuerinsert into with mix of static and table valuesHow might I execute an insert into that combines JS-side values with a select, like: ``` INSERT INTOMigration error "TypeError: Cannot read properties of undefined (reading 'getExecutor')"I am trying to run a migration using Kysely, and its returning this error: ``` file:///Users/brunocrwhere clause with lengthHow do I have a where clause with a length, e.g. `select * from data where length(prodcode) = 3`show generated sqlhow can i see what the generated sql is for a kysely query? e.g. ``` result = await db.selectFrom("Property does not exist on typeHello. I'm trying to run the following query: ```javascript result = await db.selectFrom("data") Correct type definitions for function receiving builderI have something like this and I was wondering if it's the correct way to type my helper function. Transform Postgres array into JS arrayHey, I was wondering if there's a helper or something to transform Postgres arrays `{one, two}` intoNoob Question: SQL INSERT that combines static values with a SELECT statementHey Kysely community! I'm just getting into Kysely and I have a question about how I could run the fIs there a way to execute an ExpressionBuilder?Using the expression hasDogNamed example from the docs ``` const eb = expressionBuilder<DB, 'personArgument of type 'string' is not assignable to parameter of type 'DynamicReferenceBuilder<never>'.The following statement, is giving me the error on the title ```ts fn("round", [fn.min("ld.price_btc