[Feature Request] Support query batching (prisma fluent api)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 15/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- typescript
调研方向
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,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
zenstackhq/zenstack 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
zenstackhq/zenstack#2873 ·
维护者通常 1 天内回复
-
runtime
难度 2/5 1-3 小时 新手友好度 78/100
zenstackhq/zenstack#2868 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
zenstackhq/zenstack#2694 · 3 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 68/100
zenstackhq/zenstack#2659 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
zenstackhq/zenstack#2542 · 1 条评论 ·
维护者通常 1 天内回复
查看 zenstackhq/zenstack 的全部 Issue
相似的 Issue
-
[bug] diagnostics.dumpBody:Buffer 形态请求(透传 lane)跳过 dumps/ 落盘,仅留 raw/-unknown-可能已有人在做 @ranxianglei 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 62/100
ranxianglei/billion-context#2421 · 2 条评论 ·
维护者通常 1 天内回复
-
pending triage
难度 2/5 1-3 小时 新手友好度 76/100
nuxt/test-utils#1842 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
MoonshotAI/kimi-code#4146 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
farbenmeer/tapi#531 ·
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复