What's the right way to get the type of a query?

Hi, I have this
export async function findTicketById(ticketId: string) {
const ticket = await db.query.ticketsTable.findFirst({
where: (tickets, { eq }) => eq(tickets.ticketId, ticketId),
with: {
assignedTo: true,
createdBy: true,
user: true,
},
});

return ticket;
}
export async function findTicketById(ticketId: string) {
const ticket = await db.query.ticketsTable.findFirst({
where: (tickets, { eq }) => eq(tickets.ticketId, ticketId),
with: {
assignedTo: true,
createdBy: true,
user: true,
},
});

return ticket;
}
and I'm trying to get the type of the ticket that is given back, which has a few additional types due to the "with" statements. Main reason for this is I want to have a function that cleans the response up before i send it back to the frontend and then i also want to be able to get these types over to my frontend repo. What's the best way to get the type of this query?
3 Replies
Angelelz
Angelelz8mo ago
There is a PR to implement a helper like this in drizzle
Angelelz
Angelelz8mo ago
GitHub
Implement infering table model with relations · Issue #695 · drizzl...
Prisma API: import { Prisma } from '@prisma/client' // 1: Define a type that includes the relation to Post const userWithPosts = Prisma.validator<Prisma.UserDefaultArgs>()({ include...
Paul | Blue
Paul | Blue8mo ago
Thanks! This seems to work. I also think that documentation around this (and any other type extraction) is important - the main reason I'm using Drizzle is for type safety and migrations
Want results from more Discord servers?
Add your server