typeorm / browser-example

Example how to use TypeORM in the browser with WebSQL.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Schema sync fails when reloading the page

meddario opened this issue · comments

After installing the dependencies and starting the project with npm start, the first time the database is created and populated correctly, when reloading the (or changing a file causing the page to reload), an {code: 5, message: "could not prepare statement (1 table "temporary_category" already exists)"} error shows up.

Let me know if you need more informations.

Sorry, for the long delay. This is a known issue we have with the WebSQL driver. We introduces sql.js driver as a replacement for now and will work on fully supporting WebSQL

Ok, i'll try the sql.js approach, my goal was to create a testing environment for a ionic/typeorm app using using a sql-enabled browser (Chrome).

You can still create a testing environment, just not with websql

Ok!

Just a curiosity: what's the exact problem with websql? With a bit of background on the issue maybe I can try to give a look!

The problem with with WebSql ist, that (at least in chrome) PRAGMA calls are not supported, which is how we get information about columns and primary keys in a "normal"/fully supported sqlite database. You can see the code, that is used in AbstractSqliteQueryRunner. The only option for Websql would be to filter out information about each column from the insert statement (stackoverflow) but I'm not sure, how reliable that will be.

@meddario Do you have a working example with sql.js?

I think that the main typeorm repository has some information about sql.js, this issue was about WebSQL (which is a now-deprecated attempt to port a sqlite-like database to web browser).

There is some limited information on the sql.js connection options in the docs

I tried the sql.js approach but the file size of that library, and hence the loading time, is huge...
Furthermore, the binary data of the database is not readable in the browser.
Pity that the WebSql is removed now... We use WebSql as fallback for Ionic Development => when testing the Ionic app in the browser, we use WebSql instead of Cordova SqLite.

If you use browser version for development purpose then why should you care about loading time

Because it adds extra seconds to every change that should be tested... Angular/Ionic... all add watchers to the code and reload the browser on any change in the code.

I added a feature request that allows using the removed WebSQL driver again (I'm willing to maintain it again). Using = registering a custom driver class in the project that uses TypeORM. Could you please have a quick look at my comment in issue typeorm/typeorm#2318 ?
Thanks a lot :-)

I'm going to close this as TypeORM no longer supports WebSQL and SystemJS. This example now uses sql.js and webpack instead.