Comments (13)
Ahh I see. Let me play around and see what I can come up with.
Still interested in how you guard against db lost connection?
from hapi-plugin-mysql.
It mostly follows the hapi style guide. Just like server.app
, request.app
is made to put anything in you want.
I did went back and looked at the api (http://hapijs.com/api#request-properties) and it does seem like it would be cleaner exposed as request.plugins['hapi-plugin-mysql'].db
but that seems a bit convoluted.
Another option would be to use http://hapijs.com/api#serverdecoratetype-property-method-options so you could do request.getDb()
, request.connection()
, request.db()
or request.getConnection()
or something which would allow just getting a connection when you need it. But you would have to manually close it like when using server.getDb()
(unless I can find some way to store the connection in the plugin and close on tail somehow)
If you have any ideas/opinions on these options I would gladly listen to them. If there is going to be any change it would probably be the last one personally.
from hapi-plugin-mysql.
I totally agree on the last one, I'll try and see if there is a simple way of getting the last one to work without much change on the way it is currently being done.
By the way, how do you handle db disconnects in your code?
from hapi-plugin-mysql.
PR's welcome ;) if you can find a way to auto close the connection I can add the request method and it won't even be a breaking change :D
from hapi-plugin-mysql.
I was looking at mysql modules docs, and it seems that you can use the pool directly without concerns of releasing the connection.
Would there been a downside of adding the pool to the request and removing it on the tail?
from hapi-plugin-mysql.
This plugin already uses a pool, you do have to tell the mysql module you are done with a connection so the pool knows which connections are free to use again
from hapi-plugin-mysql.
This doesn't require a release of the connection, as it is on the pool directly.
Pooling connections
Use pool directly.
var mysql = require('mysql');
var pool = mysql.createPool({
connectionLimit : 10,
host : 'example.org',
user : 'bob',
password : 'secret'
});
pool.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
if (err) throw err;
console.log('The solution is: ', rows[0].solution);
});
from hapi-plugin-mysql.
That uses a connection per query (https://github.com/felixge/node-mysql/blob/1720920f7afc660d37430c35c7128b20f77735e3/lib/Pool.js#L184), while the plugin now gives you a connection per request.
from hapi-plugin-mysql.
Not sure what you mean by db lost connection?
from hapi-plugin-mysql.
I mean how do you recover from the database being disconnect from your server?
from hapi-plugin-mysql.
atm this plugin throws since it assumes that you always have a connection if the first one works.
I could provide a function that get's called on error so you can gracefully handle it. Now with a pool if 1 connection fails it will remove it from the pool and try another one. see https://github.com/felixge/node-mysql#server-disconnects
from hapi-plugin-mysql.
It might be of interest, So ar I haven't thought of a way to handle the db server being disconnected.
I think your way might be the correct way to do it.
from hapi-plugin-mysql.
When I have time I'll look into adding this!
from hapi-plugin-mysql.
Related Issues (10)
- An in-range update of @hapi/hoek is breaking the build 🚨 HOT 2
- An in-range update of @hapi/lab is breaking the build 🚨 HOT 5
- An in-range update of @hapi/hoek is breaking the build 🚨 HOT 9
- Clarifiaction? HOT 3
- Add test with tail usage
- An in-range update of hapi is breaking the build 🚨 HOT 5
- An in-range update of code is breaking the build 🚨
- An in-range update of hapi is breaking the build 🚨 HOT 1
- Feature request: use node-mysql2 instead of node-mysql HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hapi-plugin-mysql.