medromo
medromo
RRailway
Created by medromo on 4/10/2024 in #✋|help
Hobby plan for multiple projects
Perfect, thank you 👍🏻
6 replies
RRailway
Created by medromo on 4/10/2024 in #✋|help
Hobby plan for multiple projects
N/A
6 replies
DTDrizzle Team
Created by patochem on 11/18/2023 in #help
How to get the return Type of a query with relations?
I would create an external helper function that makes the db query and then use the return type for the public user variable
const getUser = async (id: number) => {
return await db.query.users.findFirst({
where: .....,
with: {
posts: true
}
});
};

type UserWithPosts = Awaited<ReturnType<typeof getUser>>;

class myStore {
public user: UserWithPosts;

async loadUser(id: number) {
this.user = await getUser(id);
};
};
const getUser = async (id: number) => {
return await db.query.users.findFirst({
where: .....,
with: {
posts: true
}
});
};

type UserWithPosts = Awaited<ReturnType<typeof getUser>>;

class myStore {
public user: UserWithPosts;

async loadUser(id: number) {
this.user = await getUser(id);
};
};
This should do the trick
3 replies