drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: Query api for subqueries
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Feature hasn't been suggested before.
- [x] I have verified this feature I'm about to request hasn't been suggested before.
### Describe the enhancement you want to request
I would like to be able to use query API for [subqueries](https://orm.drizzle.team/docs/select#select-from-subquery)
```ts
const sq = db.select().from(users).as('sq');
const result = await db.query.fromSub(sq).findMany({
where: {
id: 42
}
});
```
It seems that this should be possible.
The idea is simple: just to be able to use query `findMany`, `findFirst` APIs for arbitrary sub queries.
This also can be implemented as a helper function I think:
something like:
```ts
function findMany(args, subQuery) {
// obviously this would be much more complicated to handle different edge cases
return db.select().from(subQuery).where(eq(args.where.id, subQuery.id))
}
```
Would be nice to have it included in orm itself but also this could be implemented in user land using helper function and regular builder api
Contributor guide
Assessment
This issue has not been assessed yet.