Created
June 10, 2015 12:40
-
-
Save EricMcRay/6b11c003cecbdf8c3a4a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var postModel = require('../models/postModel'); | |
var mysql = require('mysql'); | |
// getAall called by routes.js file | |
app.get('/posts/:username/', [authentication.check, posts.getAll]); | |
// | |
exports.getAll = function(req, res){ | |
postModel.findByUsername(req.params.username, function(err, results){ | |
if(results.length === 0) { | |
res.sendStatus(404); | |
} else { | |
res.json(results); | |
} | |
}); | |
}; |
This file contains hidden or 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
var db = require('../database'); | |
exports.query = function(query, cb){ | |
db.connection_pool.getConnection(function(err, connection) { | |
if(err){return cb(err)} | |
connection.query(sql, cb); | |
}); | |
} |
This file contains hidden or 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
var db = require('../lib/db'); | |
var mysql = require('mysql'); | |
exports.findByUsername = function(username, cb){ | |
var sql = "SELECT * FROM wall_post WHERE ?? = ?"; | |
var inserts = ['user_username', username]; | |
sql = mysql.format(sql, inserts); | |
db.query(sql, cb); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment