Guest User

Untitled

a guest
Jun 18th, 2017
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require('mysql')
  2.  
  3. /*
  4. Usage:
  5.  
  6. const donationDAO = new DAO()
  7.  
  8. donationDAO.getUsers((users) => {
  9.     if (users.length > 0) {
  10.         console.log("There exists users")
  11.     } else {
  12.         console.log("No users exist")
  13.     }
  14. })
  15.  
  16. */
  17.  
  18. module.exports = class DAO {
  19.     constructor() {
  20.         this.con = mysql.createConnection({
  21.           host: "localhost",
  22.           user: "yourusername",
  23.           password: "yourpassword"
  24.         });
  25.  
  26.         this.con.connect(function(err) {
  27.           if (err) throw err;
  28.           console.log("DAO connected to db!");
  29.         });
  30.     }
  31.  
  32.     getUsers(cb) {
  33.         this.con.query("SELECT * FROM TABLE USERS", function (err, result) {
  34.             if (err) throw err
  35.             console.log("Result: " + result)
  36.             cb(result)
  37.         })
  38.     }
  39. }
Add Comment
Please, Sign In to add comment