K
Kysely11mo ago
Ross

Argument of type 'RawBuilder<unknown>' is not assignable to...

I have a query that looks like this: countQuery.where( 'activityId', 'in', sql(SELECT activityId FROM activities WHERE MATCH(EL_EQ_PRODUCT_DESCRIPTION) AGAINST (+"${value}" IN BOOLEAN MODE)), ); TypeScript is now showing an error that states: Argument of type 'RawBuilder<unknown>' is not assignable to parameter of type 'OperandValueExpressionOrList<Database, "activities", "activityId">'. This is with Kysely 0.27.0/0.27.1/0.27.2 and TypeScript 5.3.3 Can anyone explain what's going on here please?
Solution:
What you actually want is something like this
sql<string>`(SELECT activityId FROM activities WHERE MATCH(EL_EQ_PRODUCT_DESCRIPTION) AGAINST (${'+' + value} IN BOOLEAN MODE))`
sql<string>`(SELECT activityId FROM activities WHERE MATCH(EL_EQ_PRODUCT_DESCRIPTION) AGAINST (${'+' + value} IN BOOLEAN MODE))`
...
Jump to solution
3 Replies
koskimas
koskimas11mo ago
Did you read the release log? You need to give a type for the raw expression. By the way, that query is broken anyways. In this part:
sql`(SELECT activityId FROM activities WHERE MATCH(EL_EQ_PRODUCT_DESCRIPTION) AGAINST (+"${value}" IN BOOLEAN MODE))`
sql`(SELECT activityId FROM activities WHERE MATCH(EL_EQ_PRODUCT_DESCRIPTION) AGAINST (+"${value}" IN BOOLEAN MODE))`
${value} gets compiled into a placeholder string like $1 or ? or @1 depending on the dialect. So your query matches something agains a string "+$1"
Solution
koskimas
koskimas11mo ago
What you actually want is something like this
sql<string>`(SELECT activityId FROM activities WHERE MATCH(EL_EQ_PRODUCT_DESCRIPTION) AGAINST (${'+' + value} IN BOOLEAN MODE))`
sql<string>`(SELECT activityId FROM activities WHERE MATCH(EL_EQ_PRODUCT_DESCRIPTION) AGAINST (${'+' + value} IN BOOLEAN MODE))`
Ross
RossOP11mo ago
I did but it didn't register with me for some reason, apologies Types are once again a little bit stricter in some places. You might get type errors from code like where('first_name', '=', sqlsomething). You need to explicitly give a type for sql expressions like this sql<string>something The query does work, however. In that it returns the correct results Your recommendation for the query fails with InvalidArgument, I've reverted as the original works. Providing <number> the sql worked a treat though. Thank you
Want results from more Discord servers?
Add your server