Closed AndresKrapf closed 6 years ago
The cordova plugin that this example needs to run (cordova-sqlite-storage) doesn't work in the browser. You will have to use another driver (websql or sql.js) when you want to run your app in the browser.
Ok. I have changed the connection options in order to use websql driver (type = "websql") but it seems to ignore it, since the same error as before appears.
You have to adapt more of your connection options to use websql (size, description and version are needed), otherwise it won't compile.
If you still get same error: Could you take a look at the line in vendor.js in which it tries to call openDatabase()
. Because the object that openDatabase()
gets called on when using websql is window
that shouldn't be undefined.
Actually I am setting those options, as: type: "websql", database: "testdb.db", version: "1.0", description: "test in browser", size: 2 1024 1024, entities: [ Author, Category, Post ]
I get the same error: "Cannot read property 'openDatabase' of undefined at http://localhost:8100/build/vendor.js:143551:26"
The codeline 143551 is: _this.sqlite.openDatabase({ name: _this.options.database, location: _this.options.location }, function (db) {
It seems to ignore websql type option.
That is strange. Can you create a repo where I can look at your code and try it out?
yes, I'll do that. I see taht ionic serve command results in server: --address 0.0.0.0 --port 8100 --livereload-port 35729 --dev-logger-port 53703 --nobrowser
I guess the option "-nobrowser" could be the problem, right? where can I change that?
Here is the repo. https://github.com/AndresKrapf/typeorm-browser-ionic-example
--nobrowser
tells you whether or not a browser window will be opened. There seems to a bug because that option is always listed. It should only listed when calling ionic serve --no-open
as this starts the server but doesn't open a browser window.
Since you created a new repo it is very hard for me to find differences but I'm able to run this example which these options and ionic serve
(typeorm@0.1.9):
await createConnection({
type: 'websql',
database: 'test',
description: 'test in browser',
version: '1.0',
size: 2 * 1024 * 1024,
logging: ['error', 'query', 'schema'],
synchronize: true,
entities: [
Author,
Category,
Post
]
});
Is there anything else that you changed?
I didn't change anything else. Anyway, I did copy/paste of the connection options as you posted and it is working fine. There was an issue with the connection options. Thanks.
I could run the sample both on emulator and device, but I cannot do it on browser. I get a runtime error:
Error: Uncaught (in promise): TypeError: Cannot read property 'openDatabase' of undefined TypeError: Cannot read property 'openDatabase' of undefined at http://localhost:8100/build/vendor.js:143551:26 at new t (http://localhost:8100/build/polyfills.js:3:20014) at CordovaDriver.createDatabaseConnection (http://localhost:8100/build/vendor.js:143550:16) at CordovaDriver. (http://localhost:8100/build/vendor.js:40604:51)...
Screenshot: