Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
- var mysql = require('promise-mysql');
- var connection;
- mysql.createConnection({
- host: 'localhost',
- user: 'sauron',
- password: 'theonetruering',
- database: 'mordor'
- }).then(function(conn){
- connection = conn;
- return connection.query('select `id` from hobbits where `name`="frodo"');
- }).then(function(rows){
- // Query the items for a ring that Frodo owns.
- var result = connection.query('select * from items where `owner`="' + rows[0].id + '" and `name`="ring"');
- connection.end();
- return result;
- }).then(function(rows){
- // Logs out a ring that Frodo owns
- console.log(rows);
- });
- var mysql = require('promise-mysql');
- var connection;
- async function querySequentially(){
- connection = await mysql.createConnection({
- host: 'localhost',
- user: 'sauron',
- password: 'theonetruering',
- database: 'mordor'
- })
- var rows = await connection.query('select `id` from hobbits where `name`="frodo"');
- var result = await connection.query('select * from items where `owner`="' + rows[0].id + '" and `name`="ring"');
- console.log(result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement