typeorm / ionic-example

Example project to demonstrate TypeORM in an Ionic app
67 stars 56 forks source link

Is there any workaround to remove the error at browser? #7

Closed JeongJun-Lee closed 6 years ago

JeongJun-Lee commented 6 years ago

Whenever I do "ionic serve", I meet the error like below:

image

daniel-lang commented 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.

JeongJun-Lee commented 6 years ago

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.

daniel-lang commented 6 years ago

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",
    ...
  });
}
JeongJun-Lee commented 6 years ago

Thank you a lot.

nextlevelshit commented 6 years ago

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.

JeongJun-Lee commented 6 years ago

@nextlevelshit Hello, is it possible to use sqlite driver in Ionic without compile error?

nextlevelshit commented 6 years ago

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.

nextlevelshit commented 6 years ago

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
daniel-lang commented 6 years ago

@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.

nextbyn commented 5 years ago

@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));