var mysql = require('./db-mysql'),
    timers = require('timers');

var num = 1;

var db = new mysql.Database({
    socket: '/var/run/mysqld/mysqld.sock',
    user: 'root',
    password: 'password',
    database: 'node'
});
db.on('ready', function () {
    console.log("Database ready");
    for (var i = 0; i < 10000; ++i) {
        timers.setTimeout(execute, 5);
    }
});
db.on('error', function (err) {
    console.log("Database error: " + err);
});
db.connect();

function execute() {
    var q = db.query("SELECT COUNT(*) cnt FROM `users`", { async: true });
    q.execute(function (error, rows, cols) {
        if (error) {
            console.log('[' + num + '] Query error: ' + error);
            ++num;
            return;
        }
        console.log('[' + num +  '] Jobs count: ' + rows[0].cnt);
        ++num;
    });
}
