How to compress WebSQL database from JavaScript
I have developed an app using HTML5 + WebSQL which synchronizes data from the local database to a server.
When data is deleted, the size of the sqlite database file remains the same. I know that this contains empty space and it will be filled when new data is inserted but I would like 开发者_运维百科to keep the size as small as possible because of the limitations.
I know that the VACUUM command in sqlite can compress the database and remove unused space, but when I try to run it on the WebSQL database from JavaScript it fails with the error "logic error or missing database". Running the command from outside the browser works fine.
My questions are:
Can the VACUUM command be executed somehow from JavaScript ?
Do the browsers implement this automatically and will it be called eventually ? (can't find any documentation about this)
Thanks for any help.
Due to the abondoned/work stopped nature of WebSQL, bugs/feature requests were not - and will not - ever be honored. This same problem exists as a Chromium bug, for instance, with no response.
It appears that the worst is true of your two questions:
1: Because the vacuum command can only be run when not connected to the database, it can only be run from the command line. There is no "disconnect database and then run VACUUM" command in browsers or javascript, it seems.
2: Don't count on it. It is not clear that it will even run when it hits the max size limit, and even if it does you'll notice major slowdowns long before you hit the max size limit.
At most you might be able to send a command to a plug-in, or something outside the javascript context, that could itself run the command...it's deprecated now so it's rather a moot point. For a legacy application if you have to have the function it will have to be done outside the simple webpage/js context.
Future/modern applications use IndexedDB now; this question has been answered for legacy applications only.
精彩评论