CodeFoodPixels / node-promise-mysql

A wrapper for mysqljs/mysql that wraps function calls with Bluebird promises.
MIT License
338 stars 63 forks source link

createConnection should return a promise #1

Closed gajus closed 9 years ago

gajus commented 9 years ago

createConnection does not return a promise. While it is not necessary to know when connection to database is successful (because .query is aware of the createConnection state), it would be useful in order to catch unsuccessful connection error.

CodeFoodPixels commented 9 years ago

I'll have a look at this

CodeFoodPixels commented 9 years ago

So having had a look and a think, the only way I feel this could work would be if the promise returned the connection, so you'd handle it like so:

var mysql = require('promise-mysql');
var connection;
mysql.createConnection({
    host: 'localhost',
    user: 'sauron',
    password: 'theonetruering',
    database: 'mordor'
}).catch(function(error){
    //logs out the error
    console.log(error);
}).then(function(conn){
    connection = conn;
});

Is this what you're looking for @gajus?

CodeFoodPixels commented 9 years ago

Added in 84c7ed9fcc60a81cbc7fd3bdd6e1e4a87a1fcbe9