K
Kysely•15mo 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
bombillazo
bombillazoOP•15mo ago
koskimas
koskimas•15mo ago
You can see the same docs by hovering over the method in your IDE
bombillazo
bombillazoOP•15mo ago
thanks
koskimas
koskimas•15mo ago
Or if you use vim, then by doing something ungodly with your keyboard
bombillazo
bombillazoOP•15mo ago
The only example I see is using Case in Select clauses, any way to us it in Where clauses?
koskimas
koskimas•15mo ago
The same way Just skip the alias
bombillazo
bombillazoOP•15mo ago
Hmm Im trying this but then/else only accept 1 parameter
No description
koskimas
koskimas•15mo 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
bombillazoOP•15mo ago
oooh
koskimas
koskimas•15mo 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
bombillazoOP•15mo 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•15mo 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
bombillazoOP•15mo ago
good to know! 🙂
Want results from more Discord servers?
Add your server