Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Promise on Reactnative

I write a promise to insert data in sqlite:

var promise_insertData=new Promise(function(resolve, reject){
          db.transaction((tx) =>{
                tx.executeSql('INSERT INTO chontact (recordID,user, phone) VALUES (?,?,?)',[recordID, name, number],
                (tx, results) => {
                    var status=(results.rowsAffected > 0) ? true : false;
                    if(status)
                        resolve()
                    else
                        reject()
                    }
                );
              });
                        reject()
})

when I try to insert data I got error

promise_insertData(db,recordid,name,phone).then(function(result){
                Toast.show('ok...');
                del_item();
            }).catch(function(error){
                Toast.show('error');
              })

Error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

TypeError: (0, _$$_REQUIRE(_dependencyMap[12], "./JSfiles/functions").promise_insertData) is not a function. (In '(0, _$$_REQUIRE(_dependencyMap[12], "./JSfiles/functions").promise_insertData)(db, recordid, textinput, textinputphone)', '(0, _$$_REQUIRE(_dependencyMap[12], "./JSfiles/functions").promise_insertData)' is an instance of Promise)

>Solution :

Give this a try. You should be able to promise_insertData(stuff).then(doSomethingElse) I’m not sure about the final reject() in your code, that might be wrong.

const promise_insertData = (db, recordid, name, phone) => {
  return new Promise(function(resolve, reject){
    db.transaction((tx) =>{
      tx.executeSql('INSERT INTO chontact (recordID,user,phone) VALUES (?,?,?)',[recordid, name, phone],
      (tx, results) => {
          var status=(results.rowsAffected > 0) ? true : false;
          if(status)
              resolve()
          else
              reject()
      });
    });
    reject() // ??
  })
};
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading