Confused: connect or not to connect?
See original GitHub issueHello,
In the project that I’m working on, instead of using Sequalize I decided to do old school, since the project is small. This means I’m spending lots of time in this repo 👻 😋. And I’m confused how to talk with the DB.
On the main README.md I read:
//call
done()
to release the client back to the pool
So my brain assumes that not only I have to do connect()
at each request, but I also have to release the connection. Sounds fine to me.
But then I go hear https://github.com/brianc/node-postgres/wiki/Query, and suddenly no connection()
, and no release to be seen in the top part of the document.
In my code I made queries using both options and they work, but since I don’t see the difference I don’t know which one to chose 😃
How should I talk with the DB? 😎 To many options, and not enough explanation on the differences between all this approaches.
What I’m looking for:
- to write as little code as possible
- to have code that can handle 10,000 request a minute for example.
- to reuse the open connection as much as possible.
Which aproceh will give the best results?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:26 (2 by maintainers)
Top GitHub Comments
Take attention. From pg-pool module index.js (pool.query instance):
@johncmunson no, I mean this: app.use(function(req, res, next){ res.locals.your_database_instance = pool; next(); }); And then in your router call it for queries. let db = res.locals.your_database_instance; try{ db.query(blablabla…) }catch(error){}