Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require('mysql')
- /*
- Usage:
- const donationDAO = new DAO()
- donationDAO.getUsers((users) => {
- if (users.length > 0) {
- console.log("There exists users")
- } else {
- console.log("No users exist")
- }
- })
- */
- module.exports = class DAO {
- constructor() {
- this.con = mysql.createConnection({
- host: "localhost",
- user: "yourusername",
- password: "yourpassword"
- });
- this.con.connect(function(err) {
- if (err) throw err;
- console.log("DAO connected to db!");
- });
- }
- getUsers(cb) {
- this.con.query("SELECT * FROM TABLE USERS", function (err, result) {
- if (err) throw err
- console.log("Result: " + result)
- cb(result)
- })
- }
- }
Add Comment
Please, Sign In to add comment