Is there any benefit to putting the db connection in the context versus having it as an global var?
Can I do this?
or in this way i have a benefit?
Solution:Jump to solution
What's the benefit of using the context instead of a direct import ...
I've wondered why I should use the tRPC context instead of just importing my database singleton from a module. Is there any benefit to it?
Because of TS performance issues, I'm creating multiple functions for bigger procedures. And passing the db connection around may be an unnecessary overhead.
4 Replies
I've wondered the same thing.
If you application will grow much it might be fine to not include it in context and extract business logic out to a service. for example
challenges.service.ts
where all the DB and business logic is done in there.
Solution
What's the benefit of using the context instead of a direct import ...
I've wondered why I should use the tRPC context instead of just importing my database singleton from a module. Is there any benefit to it?
Because of TS performance issues, I'm creating multiple functions for bigger procedures. And passing the db connection around may be an unnecessary overhead.
a minute ago I found this thread but it is not clear for me
the message i took from the thread was that it doesn't really matter, BUT it could make things easier for testing