Skip to content

[FEATURE]: Query api for subqueries #5233

@valerii15298

Description

@valerii15298

Feature hasn't been suggested before.

  • 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

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions