I am using ionic 2 sqlite and I am trying to check if database is already open.
I know I can do
import { SQLite } from 'ionic-native';
...
const vm = this;
vm.db = new SQLite();
db.openDatabase({
name: 'data.db',
location: 'default'
}).then(() => {
// The database opened successfully
}, (err) => {
// Unable to open database;
// The database could already be already open
});
So the logic that I want implement is like the following
if(db.isOpen) {
query()
} else {
openDatabase().then(()=> {
query()
})
}
query() {
db.executeSql( ...
}