.$inferSelect for relations

Hello there, is there a convenient way to get the list of relations of a specific table ? Either directly or at the type level. Basically getting what the with argument accept in the rqb. Cheers o/
3 Replies
Hebilicious
HebiliciousOP12mo ago
GitHub
Feat: infer type helpers for relations by Angelelz · Pull Request #...
close #695 Added InferManyRelationalResult and InferFirstRelationalResult generic types to infer the resulting object shape. Added db.query.<tableName>.$inferFindManyArgs and db.query.<ta...
Angelelz
Angelelz12mo ago
Yeah, but check out this discussion for a workaround https://github.com/drizzle-team/drizzle-orm/discussions/1483
GitHub
Relations input · drizzle-team drizzle-orm · Discussion #1483
I have a schema that looks like somewhat like this: export const employeesSchema = pgTable('employees', { firstName: varchar('first_name', { length: 256 }), lastName: varchar('l...
Hebilicious
HebiliciousOP12mo ago
Damn I should have checked this thread, I went this route already
const relations = ['notificationTokens'] as const;
type RelationsKeys = (typeof relations)[number];
type RelationTypes = {
notificationTokens: NotificationToken[];
};

export type User = typeof S.user.$inferSelect & { [K in RelationsKeys]: RelationTypes[K] };
const relations = ['notificationTokens'] as const;
type RelationsKeys = (typeof relations)[number];
type RelationTypes = {
notificationTokens: NotificationToken[];
};

export type User = typeof S.user.$inferSelect & { [K in RelationsKeys]: RelationTypes[K] };
this is actually not bad in my usecase (making a graphql api) because I don't want to expose everything
Want results from more Discord servers?
Add your server