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-callsFunction calls | Kysely
This example shows how to create function calls. These examples also work in any
Solution:Jump to 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
1 Reply
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.https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html The error message gave no useful hints.
SelectQueryBuilder | kysely
Documentation for kysely