Closed JeongJun-Lee closed 6 years ago
please look at #6. The plugin (cordova-sqlite-storage) doesn't work in the browser. You can only run this example on a device or a simulator.
I understood. But can I do development at browser by sqljs driver instead of cordova driver as if I work on real device? If possible, pls give me a hint. Very thanks.
You can check if window.cordova
is set, in which case you are running on a device.
So your code could look something like this:
let connection;
if (window.cordova) {
// running on device/emulator
connection = await createConnection({
type: "cordova",
...
});
} else {
// running in dev mode
connection = await createConnection({
type: "websql",
...
});
}
Thank you a lot.
In my case window.cordova
was throwing errors, so I've solved it that way with this.platform.is('cordova')
:
this.platform.ready().then(async () => {
if (this.platform.is('cordova')) {
// running on device/emulator
await createConnection({
type: 'cordova',
//...
});
} else {
// running in dev mode
await createConnection({
type: 'sqlite',
//...
});
}
}
I havn't tried websql
so far, but should have that same result.
@nextlevelshit Hello, is it possible to use sqlite driver in Ionic without compile error?
For now it is not working, that is what I heard from the team. In production you can use sqlite easily, but in development sqlite would be a good alternative, but it won't work for now.
@JeongJun-Lee, for more information check these related issues: https://github.com/typeorm/typeorm/issues/169 and https://github.com/typeorm/typeorm/issues/548
The corresponding issues are also present in ionic 3. I have adapted MySQL in development environment.
Hmmmm, I've tried it with MySQL and getting a common error:
Error: Uncaught (in promise): DriverPackageNotInstalledError: Mysql package has not been found installed. Try to install it: npm install mysql --save
@nextlevelshit @JeongJun-Lee We split the drivers/databases into two types (these that run in the browser/cordova/ionic and those that can be used with nodejs). These would be (right now):
So for development (with a browser) you will have to use one of the three drivers, that support it.
@daniel-lang can you put a ConnectionOptions using websql
I can't change my driver sqljs to websql in my connectionOptions
const options: ConnectionOptions = { type: 'sqljs', autoSave: true, location: "browser", synchronize: true, entities: [ ttEntidades ] }; createConnection(options).then(connection => { }).catch(error => console.log("Data Access Error : ", error));
Whenever I do "ionic serve", I meet the error like below: