Guest User

Untitled

a guest
Dec 26th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. $ node statinquirer.js
  2. ? Which opponent do you choose? rat
  3. ? Which stat would you like to check? health
  4. connected as id 28
  5. RowDataPacket { health: 'health' }
  6. The rat's health is [object Object]
  7.  
  8. // Load the NPM Package inquirer
  9. var inquirer = require("inquirer");
  10. var mysql = require("mysql");
  11.  
  12. // Create a "Prompt" with a series of questions.
  13. inquirer
  14. .prompt([
  15. {
  16. type: "list",
  17. message: "Which opponent do you choose?",
  18. choices: ["rat", "goblin", "troll"],
  19. name: "opponent"
  20. },
  21. {
  22. type: "list",
  23. message: "Which stat would you like to check?",
  24. choices: ["health", "strength"],
  25. name: "stat"
  26. }
  27. ])
  28. .then(function(inquirerResponse) {
  29.  
  30. var connection = mysql.createConnection({
  31. host: "localhost",
  32. user: "root",
  33. password: "",
  34. database: "esg_db"
  35. });
  36.  
  37. connection.connect(function(err) {
  38. if (err) {
  39. console.error("error connecting: " + err.stack);
  40. return;
  41. }
  42. console.log("connected as id " + connection.threadId);
  43. });
  44. //*******************
  45.  
  46. connection.query("SELECT '" + inquirerResponse.stat + "' FROM opponents WHERE name='"
  47. + inquirerResponse.opponent + "'" , function(err, result) {
  48.  
  49. // We then begin building out HTML elements for the page.
  50. console.log(result);
  51.  
  52. console.log("The " + inquirerResponse.opponent + "'s " + inquirerResponse.stat
  53. + " is " +
  54. result);
  55. });
  56.  
  57. // connection.query("SELECT * FROM opponents", function(err, result) {
  58.  
  59. // // We then begin building out HTML elements for the page.
  60. // console.log(result);
  61. // var answer = result;
  62. // console.log(result);
  63. // });
  64. // //this version works, so its not a problem with the connection
  65.  
  66.  
  67. //answer/result comes back undefined
  68. })
Add Comment
Please, Sign In to add comment