pwalczyszyn / express-myconnection Goto Github PK
View Code? Open in Web Editor NEWConnect/Express middleware that auto provides mysql connections
License: Apache License 2.0
Connect/Express middleware that auto provides mysql connections
License: Apache License 2.0
Node HTTP API defines two events to finish the response: finish
and close
. When res.end()
is called node triggers the finish
event, but if the request terminates unexpectedly (i.e.: the client reloads the page before the response is sent) close
is triggered instead.
Proxying res.end()
does not take into account the close
event and it causes a connection leak. The strategy should be changed to listen for both finish
and close
events.
Hi
i am trying to connect mysql, but it is showing me req.getConnection is not a function
Bellow is the code snipet which i have used.
In app.js
var mysql = require('mysql'), connection = require('express-myconnection'), dbOptions = { host: 'localhost', user: 'root', password: '', port: 3306, database: 'nodejs' }; app.use(connection(mysql, dbOptions, 'request'));
In Customers.js
exports.list = function(req, res, next) { req.getConnection(function(err, connection) { if (err) return next(err); connection.query('SELECT * FROM customer', function(err, rows) { if (err) console.log("Error Selecting : %s ", err); res.render('customers', { page_title: "Customers - Node.js", data: rows }); }); }); };
Can you please check what is have done wrong. I am pretty new in nodejs, so may be i am missing something.
If you want to check my complete package, please follow bellow URL, i have push all code in my git repository
https://github.com/chiraggmodi/nodeCrud
Wonder how one would create a LocalStrategy (that autenticates users againsts a user table in a database) using express-myconnection?
There is no req object in this case.
How i can use this in my custom function ๐
function dbcheck() {
getConnection(function (err, connection) {
connection.query('SELECT *FROM users ', function (err, results) {
if (err) return next(err);
return results;
});
});
}
var config = { db: { host: 'localhost', user: process.env.DB_USER || 'root', password: process.env.DB_PWORD || '', port: process.env.DB_PORT || 3306, database: process.env.DB_NAME || 'xxx', multipleStatements: true } } app.use(myConnection(mysql, config.db, 'pool'));
Gives me the following error:
ReferenceError: pool is not defined at IncomingMessage.req.getConnection (/Users/scottvanlooy/Development/Node/fcnode/node_modules/express-myconnection/lib/express-myconnection.js:86:21) at getContent (/Users/scottvanlooy/Development/Node/fcnode/routes/index.js:36:7) at exports.index (/Users/scottvanlooy/Development/Node/fcnode/routes/index.js:55:2) at callbacks (/Users/scottvanlooy/Development/Node/fcnode/node_modules/express/lib/router/index.js:164:37) at param (/Users/scottvanlooy/Development/Node/fcnode/node_modules/express/lib/router/index.js:138:11) at pass (/Users/scottvanlooy/Development/Node/fcnode/node_modules/express/lib/router/index.js:145:5) at Router._dispatch (/Users/scottvanlooy/Development/Node/fcnode/node_modules/express/lib/router/index.js:173:5) at Object.router (/Users/scottvanlooy/Development/Node/fcnode/node_modules/express/lib/router/index.js:33:10) at next (/Users/scottvanlooy/Development/Node/fcnode/node_modules/express/node_modules/connect/lib/proto.js:193:15) at Object.loc [as handle] (/Users/scottvanlooy/Development/Node/fcnode/node_modules/loc/lib/i18n.js:129:3)
Not sure why, any ideas?
Connection pool does not work with mysql, when the wait_timeout in mysql the server disconnects. This causes an error to be thrown. Express connection does not reacquire connection. I can find no comments or solutions in any forum on this.
if we have transactional database and datamart/reporting db can this support having multiple pools available in some way?
first I guess can a given controller/service/router getting a request use getConnection with some qualifier stating which datasource to use?
could it support getting multiple
I am implementing long polling in express and my clients can timeout and drop the connection.
In this case the connection is leaked using request strategy. I've solved in my long polling code with:
req.on('close', function(err) {
req.getConnection(function(err, connection) {
connection.end();
});
});
Please help me config connection to database replication (master & slave)
Thanks
Sid
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.