Created
June 11, 2011 02:45
-
-
Save drewlesueur/1020188 to your computer and use it in GitHub Desktop.
node mysql lasting connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to make a lasting connection in node mysql | |
client = null | |
db = null | |
tries = 0 | |
makeLastingConnection = => | |
tries++ | |
client = new Client | |
client.host = config.db.host | |
client.user = config.db.user | |
client.password = config.db.password | |
db = new MySqlHelper client | |
console.log "trying to make a lasting connection for the #{tries} time" | |
client.connect (err) => | |
if err | |
console.log "error connecting to db" | |
return _.wait 5000, makeLastingConnection | |
client._connection.on "close", () => | |
_.wait 1000, makeLastingConnection | |
client.query("Use #{config.db.db};") | |
makeLastingConnection() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment