title: How to insert Data into sqlite Database using a generic function
body: <p>The function I'm coding will be called from other javascript file and the fields and values will be passed to the function including the table name. But when I run the function it just gives error without this error message</p>
  
  <pre><code>    We have encounter an Error WebSQLTransaction { "_complete": false, "_error": null, "_running": true, "_runningTimeout": false, "_sqlQueue": Queue { "first": undefined, "last": undefined, "length": 0, }, "_websqlDatabase": WebSQLDatabase { "_currentTask": TransactionTask { "errorCallback": [Function anonymous], "readOnly": false, "successCallback": [Function anonymous], "txnCallback": [Function anonymous], }, "_db": SQLiteDatabase { "_closed": false, "_name": "mydb.db", }, "_running": true, "_txnQueue": Queue { "first": Object { "item": TransactionTask { "errorCallback": [Function anonymous], "readOnly": false, "successCallback": [Function anonymous], "txnCallback": [Function anonymous], }, "next": Object { "item": TransactionTask { "errorCallback": [Function anonymous], "readOnly": false, "successCallback": [Function anonymous], "txnCallback": [Function anonymous], }, "next": Object { "item": TransactionTask { "errorCallback": [Function anonymous], "readOnly": false, "successCallback": [Function anonymous], "txnCallback": [Function anonymous], }, }, }, }, "last": Object { "item": TransactionTask { "errorCallback": [Function anonymous], "readOnly": false, "successCallback": [Function anonymous], "txnCallback": [Function anonymous], }, }, "length": 3, }, "version": "1.0", }, }
  </code></pre>
  
  <p>So am building this using javascript React native and am using the expo SDK. Expo ships in the SQLite module, Again what am doing is to build a function that can be called from anywhere in the code and it some data into the database. </p>
  
  <pre><code>   export const insert = (tbl, fields, values) =&gt;{
      const query = "insert into ${tbl} (${fields}) values (${values});";
      console.log(query);
      //it looks fine to me
      db.transaction(trx =&gt; {
          let trxQuery = trx.executeSql(
             query
          ,[values],(data)=&gt; console.log('we made it',data),(err)=&gt;console.log('We have encounter an Error', err))
          console.log(trxQuery); // retruns undefined
      })
  }
  </code></pre>
  
  <p>This is how I called the function </p>
  
  <pre><code>    const personObj = JSON.parse(personDetails);
          Object.keys(personObj).map(i =&gt; 
              insert('users','name, address, hash', [personObj[i].name, personObj[i].address, personObj[i].hash])
          )
  </code></pre>
  
  <p>I expect to get a console log of <code>we made it</code> and information concerning the data we inserted. Thanks for your assistance</p>