K
Kysely2y ago
mike

Which approach is better for coalesce and similar functions?

The fn and raw looks to me familiar as in sequelize there is fn and literal. What is the right approach for using coalesce as follows? ... AND COALESCE("Article"."AuthorCode", '1ee15c10-606b-6b81-db96-00f59ee1f648') = COALESCE("Article2"."AuthorCode", '1ee15c10-606b-6b81-db96-00f59ee1f648')
5 Replies
Igal
Igal2y ago
Hey 👋 Have you tried the built-in type-safe eb.fn.coalesce function? https://github.com/kysely-org/kysely/blob/master/test/node/src/coalesce.test.ts check out all the variations under test
mike
mikeOP2y ago
omg, haven't noticed. 🤦‍♂️ I suppose it's exactly what I wanted so I there would not be such a helper in fn, typically window functions such as RANK or PARTITION - would you recommend raw sql only?
Igal
Igal2y ago
either raw sql or using eb.fn<Type>('functionName', [arg1, arg2]) or using eb.fn.agg<Type>('functionName', [arg1, arg2]) the latter provides aggregate function builder API, like distinct, over, etc.
mike
mikeOP2y ago
perfect, I'll test all of them! thanks!
Igal
Igal2y ago
https://github.com/kysely-org/kysely/blob/master/test/typings/test-d/coalesce.test-d.ts this better represents the type behavior of coalesce I'm giving you test links because we can't just put all of these examples in docs
Want results from more Discord servers?
Add your server