When I use SQLite, need re-open the dataase all time, andi this is too bad. How I can create/set a global variable with SQLite instance to share it between components?
Simple example:
app/app.ts
export class MyApp {
constructor(public platform: Platform) {
this.platform.ready().then(() => {
@SetGlobal();
let databaseInstance = new SQLite();
});
}
}
home/home.ts
export class HomePage {
constructor(public platform: Platform, databaseInstance) {
databaseInstance.then(() => {
databaseInstance.executeSql('create table demo(name VARCHAR(32))', {}).then(() => {
}, (err) => {
console.error('Unable to execute sql: ', err);
});
}, (err) => {
console.error('Unable to open database: ', err);
});
}
}