title: how to use promise with a sql request
body: <p>I am dispatching an action when a function is called , it should try to pass a file/image to another function to upload it to a local folder  once done try to make insert into sqlite database , to ensure that these steps will be done one by one , I have used Promises , my issue is that the image is uploaded to local folder but  insertion into database fails , would please help to find how I can correct get insertion into database done .</p>
  
  <p>here is my code :</p>
  
  <pre><code>export const addPosts = ( imageName , data,title,categ,idSubCateg) =&gt; {
    const idSubCat = idSubCateg ? idSubCateg : 0;
    return (dispatch) =&gt; {
  
      dispatch({ type: ADDING_POST });
      new Promise((resolve, reject) =&gt; {   
        uploadImage(imageName, data) // this for upload image to local folder
        const postToSave = { title, imageName };                 
        resolve(registerDataIntoDtabase(dispatch,imageName,title,categ,idSubCat));
        reject(handleError(dispatch, 'an Error Occured'));
      });
    }
  }
  
  const registerDataIntoDtabase = (dispatch,title,imagenmae,categ,idSubCat) =&gt; {
    //insert into database
    new Promise((resolve, reject) =&gt; { 
      db.transaction((tx) =&gt; {
          tx.executeSql('INSERT INTO rooms (room,idHouse,title,idOwner) VALUES (?,?,?,?)', [imagenmae,categ,title,idSubCat], (tx, results) =&gt; {
            resolve(dispatch({ type: ADDING_SUCCESS }));
            reject(handleError(dispatch, error.message));
          })
      });
    });
  }
  </code></pre>