How to check if a row exists in Drizzle?

According to this StackOverflow post: https://stackoverflow.com/questions/7471625/fastest-check-if-row-exists-in-postgresql The most performant way to check if a row exists is as follows:
SELECT EXISTS(SELECT 1 FROM foo WHERE id = 123)
SELECT EXISTS(SELECT 1 FROM foo WHERE id = 123)
How do you accomplish this in Drizzle?
4 Replies
Angelelz
Angelelz12mo ago
You'll have to use raw sql.
Angelelz
Angelelz12mo ago
Select without from is not supported yet in drizzle. But the PR is out, should come pretty soon. https://github.com/drizzle-team/drizzle-orm/pull/1405
GitHub
Feat: select without from and with recursive by Angelelz · Pull Req...
This will close #372 and will close #209. Also related to #1215? This PR depends on #1218. Upon merging, It will be possible to write a select statement without the .from() method. That will make p...
UltraWelfare
UltraWelfare12mo ago
This is still open, is there any progress on this? I figured you can do
const data = await db.select({
exists: sql<number>`1`
}).from(projects).where(eq(projects.name, value));
// check data.length
const data = await db.select({
exists: sql<number>`1`
}).from(projects).where(eq(projects.name, value));
// check data.length
Want results from more Discord servers?
Add your server