Reputation: 43
Im not getting the result of a database query, instead im getting 'undefined'
Can someone pls tell me what im missing here?
DbManager.js
getCameras() {
db.transaction(tx => {
tx.executeSql('select * from cameras;', [],
(_, result) => { return result.rows._array });
});
}
App.Js
async componentDidMount() {
dbManager.createDatabase();
//dbManager.insertCamera('Canon Canonet QL 17');
let data = await dbManager.getCameras();
console.log(data);
}
Upvotes: 2
Views: 73
Reputation: 31655
You need to return a Promise
and resolve
with the result.
getCameras() {
return new Promise((resolve, reject) => {
db.transaction(tx => {
tx.executeSql('select * from cameras;', [], (_, result) => {
resolve(result.rows._array)
});
});
})
}
async componentDidMount() {
dbManager.createDatabase();
//dbManager.insertCamera('Canon Canonet QL 17');
let data = await dbManager.getCameras();
console.log(data);
}
Upvotes: 1