Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. // call function
  2. myQuery(1)
  3. .then((queryData)=>{
  4. console.log(queryData);
  5. })
  6. .catch((error)=>{
  7. console.log(error);
  8. });
  9.  
  10. // query function
  11. myQuery(account_id){
  12. return new Promise( (resolve, reject) => {
  13. const sql = "SELECT * FROM user WHERE account_id = ?";
  14. this.db_connection.query(sql, [account_id], function(error, rows) {
  15. if (error)
  16. {
  17. const error = error.stack;
  18. reject(error);
  19. }
  20. if(rows.length === 0){
  21. reject('user is not exist');
  22. }else{ // user is exist
  23. resolve(rows);
  24. }
  25. });
  26. });
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement