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

Support basic custom queries w/automatic batching #375

Closed
stephenh opened this issue Jul 23, 2022 · 1 comment
Closed

Support basic custom queries w/automatic batching #375

stephenh opened this issue Jul 23, 2022 · 1 comment

Comments

@stephenh
Copy link
Collaborator

stephenh commented Jul 23, 2022

I.e. something like:

const row = em.customBatchedQuery(`
  SELECT
    ps.id,
    COUNT(*) as total_pi, 
    SUM(CASE pi.bought_out_status_id WHEN 1 THEN 1 ELSE 0 END) as bought_out_pi
  FROM project_stages ps
  LEFT OUTER JOIN project_items pi ON pi.project_stage_id = ps.id 
  WHERE ps.id IN (?)
  GROUP BY ps.id
`, ps.untaggedIdOrFail);

If invoked with N ps.untaggedIdOrFails in the same event loop, this would be 1 DB query.

The convention would be that whatever the input parameter is (the single number/text of the 2nd param), must be the 1st column of the custom query, so that the implementation would knows how to partition out the single big result back to each individual caller.

This is stock dataloader functionality, the idea is to just provide a nicer API that is also scoped to the EntityManagers existing connection/lifecycle/etc.

@stephenh
Copy link
Collaborator Author

We have em.getLoader which I think is good enough for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant