getting proper max userId

This commit is contained in:
Arjun Patel
2018-07-27 22:35:28 -07:00
parent cb8aabe033
commit 7ee97d4771
+10 -1
View File
@@ -19,7 +19,6 @@ app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html'); res.sendFile(__dirname + '/index.html');
}); });
function handleDisconnect() { function handleDisconnect() {
con = mysql.createConnection(db_config); // Recreate the connection, since con = mysql.createConnection(db_config); // Recreate the connection, since
// the old one cannot be reused. // the old one cannot be reused.
@@ -42,6 +41,16 @@ function handleDisconnect() {
} }
handleDisconnect(); handleDisconnect();
app.get('/userid', function (req, res) {
var currUserId;
con.query('SELECT max(userId) from messages;', function (err, result, fields) {
if (err) throw err;
currUserId = result + 1;
});
res.json(currUserId);
});
io.on('connection', function (socket) { io.on('connection', function (socket) {
console.log('Client connected: ' + socket.id); console.log('Client connected: ' + socket.id);