1

This is a async.parallel method to display the shop information and their corresponding images:

 function listshops(callback)
        {  
        async.parallel([
        myFirstFunction,
        mySecondFunction,            
        ], function (err,results) {

        console.log(results);
       });


function myFirstFunction(callback) {

        client.connection.query('select * from shop',function(err,data1){
        callback(null,data1);
    });
}


function mySecondFunction(callback) {
    client.connection.query('select * from image',function(err,data2){
        callback(null,data2);

    });
}

1)My tables=>shop and images: https://i.sstatic.net/F20MU.png

2)output getting for my code.But this is not the output i expected: https://i.sstatic.net/ltJpf.png

3)expected output: https://i.sstatic.net/xAmvu.png

0

2 Answers 2

4
function listshops(callback)
{   
 var array=[3,4];
  async.each(array,function(dat,callback){

     async.parallel([

         function(callback){
            client.connection.query('select * from shop where shopId=?',dat,function(err,data1){
            callback(null,data1);

           });
        },       

         function (callback) {
            client.connection.query('select * from image where shopId=?',dat,function(err,data2){
            callback(null,data2);

           });
        }
     ],
     function(err,data)
     {
     console.log(data);

     });
 });

}
Sign up to request clarification or add additional context in comments.

Comments

1

The program is working correctly for the code you have written.

async.parallel will run all the functions in the function array given to it, in parallel, and return the results of all the functions in the same order as the order of the functions in the function array.

For your requirement, you can have only one function which executes the join sql query to given the required output.

1 Comment

Yes we can do it by SQL join,but the problem is that i have multiple data in the image table and i want to fetch that as a separate array. And i need the output in the format that i given in the question. I think it is possible with async.each.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.