How can I select array of users and their related projects (many) as array?

Imagine I have these schemas:
// users table
export const users = pgTable("users", {
  id: uuid("id").primaryKey().defaultRandom(),
  name: text("name"),
});

// projects table
export const projects = pgTable("projects", {
  id: uuid("id").primaryKey().defaultRandom(),
  userId: uuid("user_id").references(() => users.id),
  title: text("title"),
});

How can I select all users, and their related projects?
Was this page helpful?