How to get another linked tables count?

I am new to Drizzle ORM and I wanted to get another tables data in my api.

This is my api
import { eq } from "drizzle-orm";

export default eventHandler(async (event) => {
  const session = await requireUserSession(event);
  const collections = await useDb()
    .select()
    .from(tables.collections)
    .where(eq(tables.collections.userId, session.user.id))
    .all();
  return collections;
});


I have another table called emails, where the collection tables id is the primary key in the email table with a column called collectionId, how do I get the emails tables count linked to this specific collection?

CC: @alexblokh @Andrew Sherman
Was this page helpful?