Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Feature Request] Support query batching (prisma fluent api)

未关闭
#2,535 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
15/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
typescript
领域
backend, database

调研方向

This asks for query batching (a dataloader-style layer) so that per-parent lookups issued in the same tick collapse into one WHERE id IN (...) query, and it notes the Prisma fluent API was not ported during the Kysely rewrite. Start by reading how the current query engine executes findMany/findUnique calls and where a per-tick queue could be hooked in, then look at how Prisma's fluent API batches. Nothing here names a file or a test, so expect design discussion before code; done means concurrent per-parent queries produce a single batched SQL statement.

由索引模型根据 Issue 内容生成。

描述

Is your feature request related to a problem? Please describe.
When using any orm for a graphql server, there is a common n+1 problem. E.g. consider this query which fetches all users with their posts:

query {
  users {
    username
    posts {
      name
    }
  }
}

The way a common graphql server resolves this is by first fetching all users and then for each executing a query to fetch his posts, the calls to the zenstack orm are equivalent to:

db.user.findMany();
db.post.findMany({ where: { user_id: 1 } });
db.post.findMany({ where: { user_id: 2 } });
db.post.findMany({ where: { user_id: 3 } });

Which corresponds to roughly these sql queries (n+1 queries):

SELECT * FROM users;  -- user ids: 1, 2, 3
SELECT * FROM posts WHERE user_id = 1;
SELECT * FROM posts WHERE user_id = 2;
SELECT * FROM posts WHERE user_id = 3;

In prisma there is an integrated dataloader which automatically batches similar queries in the same js tick, so it results in the following (2 queries) when using the fluent API:

db.user.findMany();
db.user.findUnique({ where: { id: 1 } }).posts();
db.user.findUnique({ where: { id: 2 } }).posts();
db.user.findUnique({ where: { id: 3 } }).posts();
SELECT * FROM users;  -- user ids: 1, 2, 3
SELECT * FROM posts WHERE user_id IN (1, 2, 3);

For that there is the fluent API, which is (per discussion on discord) not ported with the kysely rewrite.

Describe the solution you'd like

The way prisma does it may not be that intuitive and I do not see a reason why only findUnique calls get used for batching. So it would be a great addition if zenstack could support batching and also of more than findUnique calls when they have parameters in common.

Describe alternatives you've considered

Using a custom dataloader implementation ontop of zenstack orm

Additional context
/

主要语言
TypeScript
星标
2.9k
派生
157
平均合并
11 小时 42 分钟
30 天内合并 PR
20

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

zenstackhq/zenstack 的其他 Issue

查看 zenstackhq/zenstack 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。