MiNiMAL
MiNiMAL
Explore posts from servers
TtRPC
Created by MiNiMAL on 11/2/2023 in #❓-help
Function to release context post-batching?
app.use('/trpc', async (req, res, next) => {
const client = await getClient()
req.client = client

await createExpressMiddleware({
router: appRouter,
createContext
})(req, res, next)

if (req.client) {
await req.client.release()
}
})
app.use('/trpc', async (req, res, next) => {
const client = await getClient()
req.client = client

await createExpressMiddleware({
router: appRouter,
createContext
})(req, res, next)

if (req.client) {
await req.client.release()
}
})
13 replies
TtRPC
Created by MiNiMAL on 11/2/2023 in #❓-help
Function to release context post-batching?
and actually...this can be simplified into just one middleware for /trpc
13 replies
TtRPC
Created by MiNiMAL on 11/2/2023 in #❓-help
Function to release context post-batching?
@Alex / KATT 🐱 I think I got this working just with express middleware. Somewhat hacky but...it's working!
app.use(async (req, res, next) => {
const client = await getClient()
req.client = client
next()
})

app.use('/trpc', async (req, res, next) => {
await createExpressMiddleware({
router: appRouter,
createContext,
})(req, res, next)
next()
})

app.use(async (req, res) => {
if (req.client) {
await req.client.release()
}
})
app.use(async (req, res, next) => {
const client = await getClient()
req.client = client
next()
})

app.use('/trpc', async (req, res, next) => {
await createExpressMiddleware({
router: appRouter,
createContext,
})(req, res, next)
next()
})

app.use(async (req, res) => {
if (req.client) {
await req.client.release()
}
})
13 replies
TtRPC
Created by MiNiMAL on 11/2/2023 in #❓-help
Function to release context post-batching?
Was there a reason for the removal of teardown? I'm happy to suggest reverting but lack the context.
13 replies
TtRPC
Created by MiNiMAL on 11/2/2023 in #❓-help
Function to release context post-batching?
Thanks, I'll peek at that. I'm also going to experiment with moving the db connection logic onto the express middleware layer
13 replies
DTDrizzle Team
Created by MiNiMAL on 10/14/2023 in #help
Front to back end type inference with parameters sent via request
Just following up with this article, apparently I’ve been fighting against a tRPC limitation this whole time! https://dev.to/zenstack/limitation-of-trpcs-type-inference-and-how-we-improved-it-47fl
16 replies
DTDrizzle Team
Created by MiNiMAL on 10/14/2023 in #help
Front to back end type inference with parameters sent via request
Really appreciate the time you’ve already taken for me - hope you have a great rest of your weekend
16 replies
DTDrizzle Team
Created by MiNiMAL on 10/14/2023 in #help
Front to back end type inference with parameters sent via request
I’ll play around over the next couple days and batch together any other questions I may have to save you time
16 replies
DTDrizzle Team
Created by MiNiMAL on 10/14/2023 in #help
Front to back end type inference with parameters sent via request
This is incredibly helpful thank you and I really appreciate the effort in pointing me in the right direction. This has been such a fun exercise in improving my typescript skills so I greatly prefer guidance like this.
16 replies
DTDrizzle Team
Created by MiNiMAL on 10/14/2023 in #help
Front to back end type inference with parameters sent via request
Gotcha ok, I’ll look into doing that in the morning, thanks so much! Do you have any guidance on utility types I should be using to build it?
16 replies
DTDrizzle Team
Created by MiNiMAL on 10/14/2023 in #help
Front to back end type inference with parameters sent via request
I definitely won't discount that I may be going about this the wrong way for what it's worth! But I'm super curious if this is feasible because it would perfect the developer experience here.
16 replies
DTDrizzle Team
Created by MiNiMAL on 10/14/2023 in #help
Front to back end type inference with parameters sent via request
No description
16 replies
DTDrizzle Team
Created by MiNiMAL on 10/14/2023 in #help
Front to back end type inference with parameters sent via request
Nested with clauses aside, what about parameters like columns that should directly affect the return value?
export const getEntityFetchProcedures = <TTableName extends TableNames>(
table: TTableName,
) => ({
discordDemo: privateProcedure
.input(
columns =>
({ columns } as {
columns: NonNullable<FindFirstArg<TTableName>>['columns']
}),
)
.query(async ({ input }) => {
const queryRef = db.query[table]
return await queryRef.findFirst(input)
}),
})
export const getEntityFetchProcedures = <TTableName extends TableNames>(
table: TTableName,
) => ({
discordDemo: privateProcedure
.input(
columns =>
({ columns } as {
columns: NonNullable<FindFirstArg<TTableName>>['columns']
}),
)
.query(async ({ input }) => {
const queryRef = db.query[table]
return await queryRef.findFirst(input)
}),
})
16 replies