Created
October 7, 2016 11:33
-
-
Save bas080/0cb33ee983d48c308964a0e6fda2b74b to your computer and use it in GitHub Desktop.
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
| // 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