K
Kysely14mo ago
Emre

How to compose functions?

I have been unable to calculate select count(id) > 0 from foo. I tried this: .select(({ eb }) => { eb(eb.fn.count('id'), '>', 0) }) Where can I find examples for these things? I looked at https://kysely.dev/docs/examples/SELECT/function-calls
Function calls | Kysely
This example shows how to create function calls. These examples also work in any
Solution:
I needed to alias the return: .select(({ eb }) => eb(eb.fn.count('id'), '>', 0).as('email_exists')) I learned this by accidentally stumbling across this note in the documentation:
You can select arbitrary expression including subqueries and raw sql snippets. When you do that, you need to give a name for the selections using the as method....
SelectQueryBuilder | kysely
Documentation for kysely
Jump to solution
1 Reply
Solution
Emre
Emre14mo ago
I needed to alias the return: .select(({ eb }) => eb(eb.fn.count('id'), '>', 0).as('email_exists')) I learned this by accidentally stumbling across this note in the documentation:
You can select arbitrary expression including subqueries and raw sql snippets. When you do that, you need to give a name for the selections using the as method.
https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html The error message gave no useful hints.
SelectQueryBuilder | kysely
Documentation for kysely
Want results from more Discord servers?
Add your server