Skip to content

Instantly share code, notes, and snippets.

@drewlesueur
Created June 11, 2011 02:45
Show Gist options
  • Save drewlesueur/1020188 to your computer and use it in GitHub Desktop.
Save drewlesueur/1020188 to your computer and use it in GitHub Desktop.
node mysql lasting connection
# 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