K
Kysely•14mo ago
bombillazo

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
koskimas
koskimas•14mo ago
You can see the same docs by hovering over the method in your IDE
bombillazo
bombillazo•14mo ago
thanks
koskimas
koskimas•14mo ago
Or if you use vim, then by doing something ungodly with your keyboard
bombillazo
bombillazo•14mo ago
The only example I see is using Case in Select clauses, any way to us it in Where clauses?
koskimas
koskimas•14mo ago
The same way Just skip the alias
bombillazo
bombillazo•14mo ago
Hmm Im trying this but then/else only accept 1 parameter
No description
koskimas
koskimas•14mo ago
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 default
bombillazo
bombillazo•14mo ago
oooh
koskimas
koskimas•14mo ago
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
.then(eb('business_id', 'is', null))
.then(eb('business_id', 'is', null))
bombillazo
bombillazo•14mo ago
aah thats it! Didn't know one could use eb directly like that, I thought it would've been
.then(eb.where('business_id', 'is', null))
.then(eb.where('business_id', 'is', null))
thanks
koskimas
koskimas•14mo ago
It 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 operation
bombillazo
bombillazo•14mo ago
good to know! 🙂
Want results from more Discord servers?
Add your server