EdgeQL

select 
  Movie {
    title,
    actors: {
      name
    } order by @credits_order limit 5,
    rating := math::mean(.reviews.score) 
  }
filter "Zendaya" in .actors.name
  
  
e.select(
  e.Movie, (movie) => ({
    title: true,
    rating: e.math.mean(movie.reviews.score),
    actors: (actor) => ({
      name: true,
      order_by: actor["@credits_order"],
      limit: 5,
    }),
    filter:
      e.op("Zendaya", "in", movie.actors.name)
  })
)

EdgeQL + TypeScript

EdgeQL + TypeScript

Prisma

e.select(
  e.Movie, (movie) => ({
    title: true,
    rating: e.math.mean(movie.reviews.score),
    actors: (actor) => ({
      name: true,
      order_by: actor["@credits_order"],
      limit: 5,
    }),
    filter:
      e.op("Zendaya", "in", movie.actors.name)
  })
)
const movies = await prisma.movie.findMany({
  select: {
    id: true,
    title: true,
    actors: {
      select: {
        person: {
          select: {
            name: true
          }
        }
      },
      orderBy: [ { credits_order: "asc" } ],
      take: 5,
    },
  },
  where: {
    actors: {
      some: {person: {is: { name: "Zendaya" }}}
    }
  },
});


const ratings = new Map(
  (await prisma.review.groupBy({
    by: ["movie_id"],
    _avg: {
      rating: true,
    },
    where: {
      movie: {
        id: {in: movies.map(m => m.id)}
      },
    },
  })
).map(el => [el.movie_id, el._avg.rating]));

for (const movie of movies) {
  // join average ratings
  movie.rating = ratings.get(movie.id)
}

EdgeQL + TypeScript

Prisma

select 
  Movie {
    title,
    actors: {
      name
    } order by @credits_order limit 5,
    rating := math::mean(.reviews.score) 
  }
filter "Zendaya" in .actors.name
  
  
const movies = await prisma.movie.findMany({
  select: {
    id: true,
    title: true,
    actors: {
      select: {
        person: {
          select: {
            name: true
          }
        }
      },
      orderBy: [ { credits_order: "asc" } ],
      take: 5,
    },
  },
  where: {
    actors: {
      some: {person: {is: { name: "Zendaya" }}}
    }
  },
});


const ratings = new Map(
  (await prisma.review.groupBy({
    by: ["movie_id"],
    _avg: {
      rating: true,
    },
    where: {
      movie: {
        id: {in: movies.map(m => m.id)}
      },
    },
  })
).map(el => [el.movie_id, el._avg.rating]));

for (const movie of movies) {
  // join average ratings
  movie.rating = ratings.get(movie.id)
}

Less code,

one DB query

low latency

More code,

three DB queries,

high latency