CASE example in docs?
Hello, where can one find an example of how to properly use CASE for query building?
We want to use it inside a Where clause at the moment.
14 Replies
The API documentation is full of examples
https://kysely-org.github.io/kysely-apidoc/interfaces/ExpressionBuilder.html#case
aaah I was looking here: https://kysely-org.github.io/kysely-apidoc/classes/CaseBuilder.html
CaseBuilder | kysely
Documentation for kysely
You can see the same docs by hovering over the method in your IDE
thanks
Or if you use vim, then by doing something ungodly with your keyboard
The only example I see is using Case in Select clauses, any way to us it in Where clauses?
The same way
Just skip the alias
Hmm Im trying this but then/else only accept 1 parameter
args.businessId
is a string. You can't use it as a column name
If you want to compare a value, you need to use eb.val(args.businessId)
to tell kysely that it's a value
The first argument is always interpreted as a column name by defaultoooh
then
and else
take one argument (a value) by default. If you want to pass a comparison there, you need to wrap it with eb
.
so
aah thats it! Didn't know one could use
eb
directly like that, I thought it would've been
thanksIt used to be. Well actually
eb.cmpr
because you can use it everywhere, not just where
but we made this shortcut because you end up making A LOT of binary operations. eb
can be used to create any binary operationgood to know! 🙂