Skip to content

Instantly share code, notes, and snippets.

@yeisoncruz16
Created October 6, 2020 01:03
Show Gist options
  • Save yeisoncruz16/d5ccb8303d769b1f7f0b3e94574570c5 to your computer and use it in GitHub Desktop.
Save yeisoncruz16/d5ccb8303d769b1f7f0b3e94574570c5 to your computer and use it in GitHub Desktop.
Simple DAO Pattern using NodeJS.js
const MySQLDAO = require("./MySQLDAO");
let MySQLDAOInstance = new MySQLDAO();
MySQLDAOInstance.findAll("users");
//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