jafar3599
jafar3599
DTDrizzle Team
Created by jafar3599 on 4/6/2025 in #help
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"),
});
// 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?
1 replies
DTDrizzle Team
Created by jafar3599 on 12/18/2024 in #help
Drizzle always says data exists even tho it can be undefined in ts.
export const selectRenter = async (name: string) => {
return db.select().from(renter).where(eq(renter.name, name));
};
export const selectRenter = async (name: string) => {
return db.select().from(renter).where(eq(renter.name, name));
};
This is my service. Then i use it like this:
const [renter] = await getRenter(name);
const [renter] = await getRenter(name);
If i hover over renter it gives the data type without undefined being a possibility. This causes for me to forget to check if the data exists or not because linter does not warn. I think im doing something wrong would like your help
7 replies