Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#2,535 0 comentarios 2 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
15/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
typescript
Área
backend, database

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
/

Lenguaje dominante
TypeScript
Estrellas
2.9k
Forks
157
Merge medio
11 h 42 min
PR fusionados (30 d)
20

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de zenstackhq/zenstack

Todos los issues de zenstackhq/zenstack

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.