Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mysql = require('mysql');
- function createDBConnection() {
- var conn = mysql.createPool({
- host: 'xxx',
- user: 'xxx',
- password: 'xxx',
- database: 'xxx'
- });
- return conn;
- }
- module.exports = function() {
- return createDBConnection;
- }
- function Dao(connection) {
- this._connection = connection;
- }
- Dao.prototype.findAll = function (callback) {
- this._connection.query('SELECT * FROM table',
- function(errors, results) {
- callback(errors,results);
- });
- };
- module.exports = function() {
- return Dao;
- }
- app.get('/products', function (req,res) {
- var connection = app.persistence.connectionFactory();
- var dao = new app.persistence.Dao(connection);
- dao.findAll(function (err, result) {
- res.format({
- json: function () {
- res.json(result);
- }
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement