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.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server