nolanlawson / cordova-plugin-sqlite-2

Native SQLite database API for Cordova/PhoneGap/Ionic, modeled after WebSQL (UNMAINTAINED)
https://nolanlawson.com/2016/04/10/introducing-the-cordova-sqlite-plugin-2/
Apache License 2.0
168 stars 28 forks source link

How to safely close the delete the database file #37

Closed yyfearth closed 8 years ago

yyfearth commented 8 years ago

I know you pointed out that close and delete db are non-goals for this project. But I still need to remove the db sometime later in order to reset all data.

I think it might be fine to use file plugin to directly delete the db file from the FS. But I'm not sure if that is possible and safe since there is no close db api.

The reason to use the sqlite plugin instead of indexedDb or WebSql for my app is that it might need a lot of storage, and need to support Android and iOS (both UIWebView and WKWebView) Currently I use the original plugin but I do not like it embedded a sqlite engine, but without support of deleting db, I cannot switch to this plugin.

Thanks

nolanlawson commented 8 years ago

Sorry yeah, I'm not planning on supporting it. You can DROP all tables and do a VACUUM afterwards instead. The SQLite files will still be there, but they will be empty.

My goal with this project is not to reinvent SQLite; it's just to shim WebSQL. Thanks for the understanding!

yyfearth commented 8 years ago

@nolanlawson I know I can drop tables, but I do not know how I can do VACUUM since there is no db.executeSql like the original plugin And I do not think

db.transaction(function (txn) {
  txn.executeSql('VACUUM', null, function (tx, res) {
    console.log(res);
  });
});

Error code 1: cannot VACUUM from within a transaction wil work.

I have to reclaim spaces either via vacuum or delete database, or the database file size will be out of control.

nolanlawson commented 8 years ago

Ah, sorry about that. Yeah maybe you can't VACUUM. In that case, SQLite will clean up the files when it decides to. Sorry, but again this isn't something I intend to support.

nolanlawson commented 8 years ago

If you'd like, you can fork this project and create your own version which adds the features you need, though. Or the original SQLite Plugin can do all these things.