KyselyK
Kysely3y ago
3 replies
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()
  );


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.
Was this page helpful?