async function resolveBook(book, connection) {
  return new Promise((resolve, reject) => {
    var query = 'select * from Book where Isbn = ' + connection.escape(book.isbn);
    connection.query(query, (err, books, result) => {
      if(err) {
        return reject(err);
      }
      if(books.length >= 1) {
        return resolve(book.isbn);
      } else {
        //Insert into Book
        var query = 'insert into Book SET ?'; 
        var data = {
          Name: book.name,
          Author: book.author, 
          Isbn: book.isbn, 
        };
        connection.query(query, data, (err, result) => {
          if(err) {
            return reject(err);
          }
          resolve(book.isbn);
        });
      }
    });    
  });
}
//Insert Book into Database if not already present
Insert Book into Database if not already present
Insert Book into Database if not already present
async function resolveBook(book, connection) {
  return new Promise((resolve, reject) => {
    var query = 'select * from Book where Isbn = ' + connection.escape(book.isbn);
    connection.query(query, (err, books, result) => {
      if(err) {
        return reject(err);
      }
      if(books.length >= 1) {
        return resolve(book.isbn);
      } else {
        var query = 'insert into Book SET ?'; 
        var data = {
          Name: book.name,
          Author: book.author, 
          Isbn: book.isbn, 
        };
        connection.query(query, data, (err, result) => {
          if(err) {
            return reject(err);
          }
          resolve(book.isbn);
        });
      }
    });    
  });
}
async function resolveBook ( book , connection ) { return new Promise ( ( resolve , reject ) => { var query = 'select * from Book where Isbn = ' + connection . escape ( book . isbn ) ; connection . query ( query , ( err , books , result ) => { if ( err ) { return reject ( err ) ; } if ( books . length >= 1 ) { return resolve ( book . isbn ) ; } else { var query = 'insert into Book SET ?' ; var data = { Name : book . name , Author : book . author , Isbn : book . isbn , } ; connection . query ( query , data , ( err , result ) => { if ( err ) { return reject ( err ) ; } resolve ( book . isbn ) ; } ) ; } } ) ; } ) ; }
Insert Book into Database if not already present
Insert Book into Database if not already present
//Insert into Book