Problems NodeJS and MySql

1

Hello I'm having problems with over connection with node-mysql2 using a connection pool. I would like to know if there is a better implementation practice, and what is the best driver to use with nodejs and mysql ?

Note: My application has longpolling and many users.

    
asked by anonymous 04.05.2016 / 22:34

1 answer

1

The most used module I believe to be mysql

I use it like this:

var mysql = require('mysql');
var pool = mysql.createPool({
    connectionLimit: 100,
    host: 'localhost',
    user: 'root',
    password: 'root',
    database: 'nomedaBD',
    debug: false,
    charset: 'utf8_unicode_ci'
});

function query (query, data, callback) {
    if (typeof data == 'function') {
        callback = data;
        data = [];
    }
    pool.getConnection(function (err, connection) {
        if (err) return onError(connection, err, callback);
        connection.query(query, data || [], function (err, rows, fields) {
            if (err) return onError(connection, err, callback);
            connection.release();
            callback.call(this, null, rows, fields);
        });
    });
}

The plugin keeps the connection to the open DB and has a pool to manage connections as in the example above.

    
05.05.2016 / 04:06