Skip to content

Instantly share code, notes, and snippets.

@bas080
Created October 7, 2016 11:33
Show Gist options
  • Select an option

  • Save bas080/0cb33ee983d48c308964a0e6fda2b74b to your computer and use it in GitHub Desktop.

Select an option

Save bas080/0cb33ee983d48c308964a0e6fda2b74b to your computer and use it in GitHub Desktop.
// In case you do not want to use promisify but do want SailsModel.query to
// return a promise.
//
// Usage: query(User, 'SELECT * WHERE id = ?', [1]);
/**
* @param {Model} model - an instance of a sails model
* @param {string} sql - a sql string
* @param {*[]} values - used to interpolate the string's ?
*
* @returns {Promise} which resolves to the succesfully queried strings
*/
function query(model, sql, values) {
values = values || [];
return new Promise((resolve, reject) => {
model.query(sql, values, (err, results) => {
if (err) {
return reject(err);
}
resolve(results);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment