Extacting where clause generation into dedicated function
I'm building up a query dynamically and need to use some of the logic embedded in where clauses from multiple functions. Therefore, I'd like to encapulate this in a separate function that can be reused but I'm struggling with the type signatures for that function.
An example of a query that I'd like to encapsulate is:
If I try to extract this into a function using the IDE it gives me:
The Database and AllSelection interfaces are not exported by kysely. I assume for the Database interface I can use the type of the row, i.e.
But I'm still stuck with what I need to do with AllSelection which makes me think there's probably a better way to solve this problem. Any thoughts, cheers?
4 Replies
Hey 👋
Something like:
Hi - thank you. That's closer, I'm now getting
TS2345: Argument of type '"activityType"' is not assignable to parameter of type 'ReferenceExpression '.
Tried dropping the generics since this will always be working on a specific table like this but the error is the same.
It's not clear to me exactly what the generic type parameters DB and TB refer to, so that could be the issueYou got DB generic wrong
this shouldn't error
https://wirekang.github.io/kysely-playground/?p=f&i=-NQ7RnBArbNCPVKKqDBu
Fantastic, that makes more sense to me, I'll try it out later. Thank you 🙏