Created
October 6, 2020 01:03
-
-
Save yeisoncruz16/d5ccb8303d769b1f7f0b3e94574570c5 to your computer and use it in GitHub Desktop.
Simple DAO Pattern using NodeJS.js
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
const MySQLDAO = require("./MySQLDAO"); | |
let MySQLDAOInstance = new MySQLDAO(); | |
MySQLDAOInstance.findAll("users"); |
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
//const mysql = require('mysql-library'); | |
const mysql = { | |
createConnection: () => { | |
return { | |
query: (query) => { | |
return query; | |
} | |
} | |
} | |
}; | |
class MySQLDAO { | |
constructor(){ | |
this.connection = this.createConnection(); | |
} | |
createConnection(){ | |
return mysql.createConnection({ | |
host: "myhost.com", | |
user: "root", | |
password: "password" | |
}); | |
} | |
findAll(table){ | |
return this.connection.query("SELECT * FROM " + table); | |
} | |
} | |
module.exports = MySQLDAO; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment