I'm having issues with Sails.JS 0.9.8. I would like to use promises with the Model.query() function (I use sails-mysql adapter).
This code will work :
User.findOne({ email: email })
.then(function(user) {
console.log(user);
});
but this one won't
User.query("SELECT email FROM user WHERE email = ?", [ email ]))
.then(function(err, rows) {
console.log(rows);
})
I get undefined for both 'err' and 'rows'.
Is it just not implemented or I am doing something wrong ? If not implemented, is there any alternative to use promises with .query() ?
Thank you in advance
You can
promisify(User.query)
yourself, just like you'd do for any other callback-based API, like:....
The
query
method is specific to sails-mysql, and doesn't support deferred objects the way that the more general Waterline adapter methods (e.g.findOne
,find
,create
, etc) do. You'll have to supply a callback as the second argument.In case you do not want to use promisify but do want SailsModel.query to return a promise.
As a hack you can monkeypatch all your models in bootstrap like this