close connection after all queries executed #27

Open
mariusradvan opened this Issue Jul 21, 2011 · 0 comments

Comments

Projects
None yet
2 participants

How can I close connection only after all queries executed successfully ?

My code is:

new mysql.Database({
    hostname: MYSQL_HOST,
    user: MYSQL_USER,
    password: MYSQL_PASS,
    database: MYSQL_DATABASE,
    reconnect: false
}).connect(function(error) {
    if(error)
        return;

    var self = this;

    for(ticker in info.tickers) {
        var tickerInfo = info.tickers[ticker];

        this.query().execute(
            'some_query_string_here'
            function(error, rows) {
                if(rows.length == 0)
                    var query = 'insert ...';
                else
                    var query = 'update...';
                self.query().execute(query);                    
            });
    }
});

I need to close the connection because I run that code in setInterval(), and if I don`t, after a while there will be a lot of open connections, so the program will crash (with error).

@ghost ghost assigned mariano Oct 23, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment