Relations input #1483
Answered
by
Angelelz
mGasiorek998
asked this question in
Q&A
Relations input
#1483
-
I have a schema that looks like somewhat like this: export const employeesSchema = pgTable('employees', {
firstName: varchar('first_name', { length: 256 }),
lastName: varchar('last_name', { length: 256 }),
email: varchar('email', { length: 256 }).unique(),
avatarId: uuid('avatar_id').unique(),
});
export const employeeRelations = relations(employeesSchema, ({ one, many }) => ({
avatar: one(photosSchema, {
fields: [employeesSchema.avatarId],
references: [photosSchema.id],
}),
photos: many(photosSchema),
})); Now i want to create a function for getting data from database with specific relations e.g async function getEmployeeById(id: string, withInput: any) {
return db.query.employeesSchema.findFirst({
where: eq(employeesSchema.id, id),
with: withInput
});
} Is there a way to get type of relations for given table (somewhat similar to how Prisma.EmployeeWhereInput would work)? |
Beta Was this translation helpful? Give feedback.
Answered by
Angelelz
Nov 9, 2023
Replies: 2 comments 7 replies
-
For those of us who don't know the feature you referred to from Prisma, can you elaborate what is it that you're looking for? |
Beta Was this translation helpful? Give feedback.
7 replies
-
This is SOOO messy! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately, drizzle doesn't have an easy to use type helper for this. You might want to submit an issue.
But there are workarounds. It you don't want to depend on Drizzle's internal types, you could use some typescript magic and come up with this:
If you want to use drizzle's internal types, here is how you can get to the same result:
Take a look at this playground to see this in action.