minty
minty
TtRPC
Created by minty on 11/16/2023 in #❓-help
Middleware or request lifecycle hook to run after procedure?
(obviously I will add the db.end() as well)
18 replies
TtRPC
Created by minty on 11/16/2023 in #❓-help
Middleware or request lifecycle hook to run after procedure?
is this sort of what you mean?
const withDb = middleware((opts) => {
const db = getServerlessDBInstance();

const result = opts.next({ ctx: { db } });

return result;
});
const withDb = middleware((opts) => {
const db = getServerlessDBInstance();

const result = opts.next({ ctx: { db } });

return result;
});
18 replies
TtRPC
Created by minty on 11/16/2023 in #❓-help
Middleware or request lifecycle hook to run after procedure?
ahh perfect ok
18 replies
TtRPC
Created by minty on 11/16/2023 in #❓-help
Middleware or request lifecycle hook to run after procedure?
got it, thank you! I will try that out
18 replies
TtRPC
Created by minty on 11/16/2023 in #❓-help
Middleware or request lifecycle hook to run after procedure?
is that what you mean?
18 replies
TtRPC
Created by minty on 11/16/2023 in #❓-help
Middleware or request lifecycle hook to run after procedure?
Oh I think I see what you mean. Like the middleware would be:
openDB()

const result = await next()

closeDB()

return result
openDB()

const result = await next()

closeDB()

return result
18 replies
TtRPC
Created by minty on 11/16/2023 in #❓-help
Middleware or request lifecycle hook to run after procedure?
Can you explain what you mean why the awaiting the next() variable? I would like the procedure to have access to the ctx.db, but not have to remember to close it
18 replies
TtRPC
Created by minty on 11/16/2023 in #❓-help
Middleware or request lifecycle hook to run after procedure?
I am using Neon (neon.tech) as my DB provider and they explicitly say to close it at the end of every request:
The Pool and Client objects must be connected, used, and closed within a single request handler. Don't create the objects outside a request handler; don't create them in one handler and try to reuse them in another; and to avoid exhausting available connections, don't forget to close them.
The Pool and Client objects must be connected, used, and closed within a single request handler. Don't create the objects outside a request handler; don't create them in one handler and try to reuse them in another; and to avoid exhausting available connections, don't forget to close them.
from here: https://neon.tech/docs/serverless/serverless-driver
18 replies