Amruth Pillai
Amruth Pillai
Explore posts from servers
DTDrizzle Team
Created by Amruth Pillai on 3/4/2024 in #help
Is there a way to re-use a specific tables columns in multiple queries across an application?
I'm trying to build a bunch of models/queries like this:
const workOrder = await db.query.workOrderTable.findFirst({
columns: {
id: true,
...
},
with: {
user: {
columns: { id: true },
with: { profile: { columns: { name: true, picture: true } } },
},
}
}
const workOrder = await db.query.workOrderTable.findFirst({
columns: {
id: true,
...
},
with: {
user: {
columns: { id: true },
with: { profile: { columns: { name: true, picture: true } } },
},
}
}
const asset = await db.query.assetTable.findFirst({
columns: {
id: true,
...
},
with: {
user: {
columns: { id: true },
with: { profile: { columns: { name: true, picture: true } } },
},
}
}
const asset = await db.query.assetTable.findFirst({
columns: {
id: true,
...
},
with: {
user: {
columns: { id: true },
with: { profile: { columns: { name: true, picture: true } } },
},
}
}
What I want to do is make the user selector reusable across the app so that anyone who queries a specific table, will be able to get the same columns and relationships from the user table, maintaining consistency.
1 replies