Advertisement
Guest User

Untitled

a guest
Feb 4th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  import * as readline from 'readline';
  2.  import * as mysql from 'mysql';
  3.  
  4.  
  5. let rl = readline.createInterface({
  6.     input: process.stdin,
  7.     output: process.stdout
  8.   });
  9.  
  10.  const connection = mysql.createConnection({
  11.      host: 'localhost',
  12.      user: 'root',
  13.      password: '',
  14.      database: 'scriptioner'
  15.     });
  16.    
  17.     connection.connect((err: string) => {
  18.         if (err) throw err;
  19.         console.log('Connected!');
  20.     });
  21.    
  22.     connection.query('SELECT * FROM questions ORDER BY RAND() LIMIT 5', (err, rowsFetched) => {
  23.         if (err) throw err;
  24.         for(let row of rowsFetched){
  25.             rl.question(row.question, (answer) => {
  26.                 console.log(row.question);
  27.             });
  28.         }
  29.     });
  30.    
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. /**
  38. connection.query('SELECT * FROM questions ORDER BY RAND() LIMIT 1', (err, rows) => {
  39.     if (err) throw err;
  40.  
  41.     console.log(rows);
  42. });
  43.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement