I am developing a mobile application with React Native. I query a database and I retrieve the data with a "SELECT" request.
The problem is that I can't get the result of this request. I would like to retrieve the result of this request is stored all the elements in a list variable
Here is the code of the "Select" request:
listProduct()
{
return new Promise((resolve) =>
{
const db = SQLite.openDatabase('database.db')
db.transaction(
tx => {
tx.executeSql('select * from FRIDGE_PRODUCT', [], (trans, result) => {
let row = result.rows;
resolve(row)
return row
});
}
);
});
}
And there is the call of this function from another script:
async function loadproduct() {
let result = await db.listProduct();
return result
}
let row = loadproduct()
The problem is that if I want to display the row variable in the console I get this:
Promise {
"_40": 0,
"_55": null,
"_65": 0,
"_72": null,
}
Whereas if I print the result directly in the function like this:
async function loadproduct() {
let result = await db.listProduct();
console.log(result)
return result
}
I get the right result:
Object {
"DATE": "10/10/2020",
"IDPRODUCT": 1,
"IMAGEURL": "imageurl",
"PRODUCTNAME": "orange",
}
How can I store the result in a varialbe ?
I try that: How to access the value of a promise? but it doesn't help me too much.