K
Kysely•14mo ago
SneakOnYou

$if with sql.raw doesn't compile

Hey, I have updated my kysely version after I deleted node_modules and npm installed and I am getting an error for the following code: const filterWhereQuery = sql.raw(LOWER("${dimensionName}") LIKE '%${filter?.toLowerCase()}%');
const query = replaceParametersInCompiledMetric(
kyselyBaseQuery
.selectFrom(`${schema}.${table}`)
.distinct()
.select(dimensionName)
.$if(!!filter, (q) => q.where(filterWhereQuery))
.$if(!!pageLimit, (q) => q.limit(pageLimit || 0).offset(pageOffset * (pageLimit || 0)))
.compile()
);
const query = replaceParametersInCompiledMetric(
kyselyBaseQuery
.selectFrom(`${schema}.${table}`)
.distinct()
.select(dimensionName)
.$if(!!filter, (q) => q.where(filterWhereQuery))
.$if(!!pageLimit, (q) => q.limit(pageLimit || 0).offset(pageOffset * (pageLimit || 0)))
.compile()
);
The error in at the 1st if where there is suddenly a type problem: Argument of type 'RawBuilder<unknown>' is not assignable to parameter of type 'ExpressionOrFactory<any, ${string}.${string}, SqlBool>'. Property 'isSelectQueryBuilder' is missing in type 'RawBuilder<unknown>' but required in type 'SelectQueryBuilderExpression<Record<string, SqlBool>>' what can I do to fix this quickly that doesn't require a huge change ? postgres
Solution:
Hey 👋 Try providing <SqlBool> generic to your sql template tag....
Jump to solution
2 Replies
Solution
Igal
Igal•14mo ago
Hey 👋 Try providing <SqlBool> generic to your sql template tag.
SneakOnYou
SneakOnYouOP•14mo ago
I explicitly set the type to the filterWhereQuery and it worked RawBuilder<SqlBool>
Want results from more Discord servers?
Add your server