Closed bbohec closed 4 months ago
Hey 👋
Yes.
import { sql } from "kysely";
const { exists } = await db
.selectNoFrom((eb) =>
eb
.exists(
eb
.selectFrom("table_name")
.where("col_name", "=", "some_value")
.select(sql`1` as any),
)
.as("exists"),
)
.executeTakeFirstOrThrow();
if (exists) {
// do stuff...
}
Here's a couple more options without as any
casts https://kyse.link/2gXq5
In Kysely, you always need to provide an alias for the selections. In my second example, I used _
as the alias. An explicit alias is needed because the column naming logic is complex and dialect-dependent if you don't provide an alias.
Thanks for you help @igalklebanov & @koskimas . Solution is working as expected.
Greetings,
Does kysely support the usage of select exist queries like
Actually I use a workaround like :