I'm using better-sqlite3 on Node
, but I suspect my questions are applicable to node-sqlite3 as well.
I basically have 2 simple questions, relating to a server-rendered website:
Do I need to explicitly call
.close()
on the database? I seem to remember reading somewhere that it will automatically close when the current scope (like the current function) exits. What if I never call.close()
in a web server scenario, taking a lot of requests?If you have a bunch of different components (authentication, authorisation, localisation, payment, etc...) and each component may or may not need to access the database throughout the lifetime of a request (which are quite short-lived, except for payment), is it better to
- have one db connection for the lifetime of the server and pass that around
- have one db connection for the lifetime of the request and pass that around
- open a new connection every time I need something, maybe 2-3 times per request (and close it either explicitly or implicitly when the function returns, if that's a thing)
Thank you