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
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", }, }
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.
export const insert = (tbl, fields, values) =>{
const query = "insert into ${tbl} (${fields}) values (${values});";
console.log(query);
//it looks fine to me
db.transaction(trx => {
let trxQuery = trx.executeSql(
query
,[values],(data)=> console.log('we made it',data),(err)=>console.log('We have encounter an Error', err))
console.log(trxQuery); // retruns undefined
})
}
This is how I called the function
const personObj = JSON.parse(personDetails);
Object.keys(personObj).map(i =>
insert('users','name, address, hash', [personObj[i].name, personObj[i].address, personObj[i].hash])
)
I expect to get a console log of we made it and information concerning the data we inserted. Thanks for your assistance