Umbranox
Umbranox
DTDrizzle Team
Created by Umbranox on 9/16/2023 in #help
Possible to reuse columns while selecting?
Apologies if this is documented somewhere and I've missed it I am currently in the process of transitioning from Prisma and follow this pattern quite often:
// This resides in a separate file for utilization across various queries
export const usersSelect = Prisma.validator<Prisma.usersSelect>()({
id: true,
name: true,
...
someRelation: {
select: {
someData: true,
},
},
});
// This resides in a separate file for utilization across various queries
export const usersSelect = Prisma.validator<Prisma.usersSelect>()({
id: true,
name: true,
...
someRelation: {
select: {
someData: true,
},
},
});
// We construct our 'where' condition based on certain options...
let usersWhere: Prisma.usersWhereInput = {
banned: false
};
if (includeInactiveUsers) {
usersWhere = {
...usersWhere,
inactive: true
}
// Execute the query
const users = await prisma.users.findMany({
select: usersSelect
where: usersWhere
...
});
// We construct our 'where' condition based on certain options...
let usersWhere: Prisma.usersWhereInput = {
banned: false
};
if (includeInactiveUsers) {
usersWhere = {
...usersWhere,
inactive: true
}
// Execute the query
const users = await prisma.users.findMany({
select: usersSelect
where: usersWhere
...
});
I am curious to know if there exists a method to adhere to this pattern using Drizzle, or if it would be advisable for me to reconsider my approach. Thanks!
28 replies