kbemaster
kbemaster
Explore posts from servers
TtRPC
Created by kbemaster on 1/22/2024 in #❓-help
Is there any benefit to putting the db connection in the context versus having it as an global var?
Can I do this?
export const challengesRouter = router({
getChallengeById: privateProcedure
.input(z.string().uuid())
.query(async ({ input }) => {
const challenge = await db.query.challengeTable.findFirst({
where: (columns, { eq }) => eq(columns.sectionId, input),
columns: {
id: true,
sectionId: true,
},
});
return challenge;
}),
});
export const challengesRouter = router({
getChallengeById: privateProcedure
.input(z.string().uuid())
.query(async ({ input }) => {
const challenge = await db.query.challengeTable.findFirst({
where: (columns, { eq }) => eq(columns.sectionId, input),
columns: {
id: true,
sectionId: true,
},
});
return challenge;
}),
});
or in this way i have a benefit?
export const challengesRouter = router({
getChallengeById: privateProcedure
.input(z.string().uuid())
.query(async ({ input, ctx }) => {
const challenge = await ctx.db.query.challengeTable.findFirst({
where: (columns, { eq }) => eq(columns.sectionId, input),
columns: {
id: true,
sectionId: true,
},
});
return challenge;
}),
});
export const challengesRouter = router({
getChallengeById: privateProcedure
.input(z.string().uuid())
.query(async ({ input, ctx }) => {
const challenge = await ctx.db.query.challengeTable.findFirst({
where: (columns, { eq }) => eq(columns.sectionId, input),
columns: {
id: true,
sectionId: true,
},
});
return challenge;
}),
});
7 replies