How to compress a WebSQL database from JavaScript

I developed an application using HTML5 + WebSQL that synchronizes data from a local database with a server.

When data is deleted, the size of the sqlite database file remains the same. I know 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 due to limitations.

I know that the VACUUM command in sqlite can compress a database and remove unused space, but when I try to run it in a WebSQL database from JavaScript, it fails with a "logical error or missing database" error. Running a command from outside the browser works great.

My questions:

  • Is there any way to execute the VACUUM command from JavaScript?

  • Do browsers do this automatically and will eventually be called? (can not find documentation about this)

Thanks for any help.

+6
source share
1 answer

Due to the non-working / terminated operation of WebSQL, there were no errors / functions requests - and will not be executed. The same problem exists as a Chromium error, for example, without an answer.

It seems that the worst relates to your two questions:

1: Since the vacuum command can only be run when it is not connected to the database, it can only be run from the command line. It seems that in browsers or javascript there is no "disconnect the database and then run the VACUUM command".

2: Do not count on it. It is not clear that it will work even with the maximum size of the maximum size, and even if this happens, you will notice a significant slowdown long before you press the maximum size limit.

In the best case scenario, you can send a command to a plug-in module or something outside the javascript context that can run the command itself ... now it is deprecated, so it’s pretty controversial. For an outdated application, if you need to have a function, you need to do this outside of the simple context of webpage / js.

Future / current applications use IndexedDB; This question was answered only for legacy applications.

+4
source

Source: https://habr.com/ru/post/893171/


All Articles