Created
November 2, 2019 18:34
-
-
Save arielivandiaz/f2094ec50e16f81a1a64b02f5a7cf9e7 to your computer and use it in GitHub Desktop.
Async function for SQL
This file contains 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
let getUser = async (userId) => { | |
let promise = new Promise((resolve, reject) => { | |
sql.query("SELECT * FROM `users` WHERE `id`=" + userId).then((userInfo) => { | |
resolve(userInfo); | |
}).catch((reject) => { //Sql reject | |
reject(reject); | |
}); | |
}); | |
return await promise; | |
} | |
let printUsername = async (id) => { | |
var user = await getUser(id); | |
console.log(user.name); | |
} | |
printUsername(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment