Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

close connection after all queries executed #27

Open
mariusradvan opened this Issue · 0 comments

2 participants

@mariusradvan

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).

@mariano mariano was assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.