Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
  2.  
  3. var mysql = require('promise-mysql');
  4. var connection;
  5.  
  6. mysql.createConnection({
  7.     host: 'localhost',
  8.     user: 'sauron',
  9.     password: 'theonetruering',
  10.     database: 'mordor'
  11. }).then(function(conn){
  12.     connection = conn;
  13.     return connection.query('select `id` from hobbits where `name`="frodo"');
  14. }).then(function(rows){
  15.     // Query the items for a ring that Frodo owns.
  16.     var result = connection.query('select * from items where `owner`="' + rows[0].id + '" and `name`="ring"');
  17.     connection.end();
  18.     return result;
  19. }).then(function(rows){
  20.     // Logs out a ring that Frodo owns
  21.     console.log(rows);
  22. });
  23.  
  24. var mysql = require('promise-mysql');
  25. var connection;
  26.  
  27. async function querySequentially(){
  28.     connection = await mysql.createConnection({
  29.         host: 'localhost',
  30.         user: 'sauron',
  31.         password: 'theonetruering',
  32.         database: 'mordor'
  33.     })
  34.     var rows = await connection.query('select `id` from hobbits where `name`="frodo"');
  35.     var result = await connection.query('select * from items where `owner`="' + rows[0].id + '" and `name`="ring"');
  36.     console.log(result);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement