How to delete a database in WebSQL programmatically?

Derek 朕會功夫 picture Derek 朕會功夫 · Aug 25, 2011 · Viewed 57.3k times · Source

I am new to Web SQL database and I use it to save data in a local database in a web page.

 I can create a database by

var db = openDatabase('database', '1.0', 'my database', 2 * 1024 * 1024);

 and I can create a table by doing this

db.transaction(function (tx) {
  tx.executeSql('CREATE TABLE IF NOT EXISTS mytable (blah,blah)');
});

 I can delete the table by

db.transaction(function (tx) {
  tx.executeSql('DROP TABLE mytable');
});

 but is there a way to delete the database programmatically?

Answer

i_a picture i_a · Mar 25, 2013

Using PersistenceJS there is a persistence.reset API which will wipe the database clean. PersistenceJS Site

For developing / testing purposes, you can view content and delete webSQL, IndexedDB, cookies, etc by searching for your domain name at this URL in Chrome:

chrome://settings/cookies

There, you can delete all the storage for a domain or just certain local storage entities. Yes, the URL implies just 'cookies', but the interface at this URL includes all types of offline storage.

It would be great I think if the Chrome developer tools interface had the ability to right-click and delete a data storage entity in the Resources tab along with inspecting the content. But for now, all I know of is the settings/cookies URL.