Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]: Joins relational queries with select APIs #3945

Open
1 task done
zoriya opened this issue Jan 13, 2025 · 0 comments
Open
1 task done

[FEATURE]: Joins relational queries with select APIs #3945

zoriya opened this issue Jan 13, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@zoriya
Copy link

zoriya commented Jan 13, 2025

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 have a query that would be way easier with the query api (something like this example bellow):

db.query.movies.findFirst({
	where: eq(movies.id, 12),
	with: {
		studio: true,
		staff: true,
	},
})

but i need this query to be joined to another table with a manual subquery. This prevents me from using the query api completly. I'd love to be able to do something like:

db.query.movies.findFirst({
	where: eq(movies.id, 12),
	join: {
		translation: leftJoin(
			// a complicated query that we don't want to handle with the simples filters available in `with`.
			db.select().from(movieTranslations).where(...).leftJoin(...),
			eq(movies.id, movieTranslations.id)
		),
	},
	with: {
		studio: true,
		staff: true,
	},
})

This would make a sql like this:

select *, translation.* from movies
# the complicated query
left join (select * from "moviesTranslation" ...) as translation on movies.id == translation.id
# the other joins needed for with
left join lateral (select json(...) from studio) on true
...

Since optional joins (#1533) are not available in drizzle right now, making something similar with the query builder is way less plesant than this query api.

@zoriya zoriya added the enhancement New feature or request label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant