Skip to content

Instantly share code, notes, and snippets.

@getnamo
Created April 8, 2019 20:39
Show Gist options
  • Save getnamo/d21b42de4384bdba339120e3064ab9da to your computer and use it in GitHub Desktop.
Save getnamo/d21b42de4384bdba339120e3064ab9da to your computer and use it in GitHub Desktop.
sample sql query callback on node.js
//assuming you're using https://www.npmjs.com/package/mysql
const mysql = require('mysql');
const con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword",
database: "mydb"
});
socket.on('sqlQuery', function(queryData, callback){
//we assume you pass a json with
//{"column": "*", "table": "users", "condition":"User=Bob"}
//run the query
con.query("SELECT" + queryData.column + " FROM " + queryData.table + " WHERE " + queryData.condition, function (err, result, fields) {
if (err) throw err;
console.log(result);
//callback with result to ue4
callback(result);
});
});
@UgoBrocardOfficiel
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment