Querying Best Practices?
Just want to discuss query best practices.
And since I only need the nested relations
const userAccount = await db.query.accounts.findFirst({
where: eq(accounts.id, userId),
with: {
activeProfile: {
with: {
savedShows: {
where: eq(myShows.id, input.id),
limit: 1, // Does using limit matter here? It should speed up query right?
},
},
},
},
})const userAccount = await db.query.accounts.findFirst({
where: eq(accounts.id, userId),
with: {
activeProfile: {
with: {
savedShows: {
where: eq(myShows.id, input.id),
limit: 1, // Does using limit matter here? It should speed up query right?
},
},
},
},
})And since I only need the nested relations
const userAccount = await db.query.accounts.findFirst({
columns: {}, // Would this matter? Does it speed up queries? It would transfer less data but is that all?
where: eq(accounts.id, userId),
with: {
activeProfile: {
with: {
savedShows: {
where: eq(myShows.id, input.id),
limit: 1,
},
},
},
},
})const userAccount = await db.query.accounts.findFirst({
columns: {}, // Would this matter? Does it speed up queries? It would transfer less data but is that all?
where: eq(accounts.id, userId),
with: {
activeProfile: {
with: {
savedShows: {
where: eq(myShows.id, input.id),
limit: 1,
},
},
},
},
})