Last active
March 11, 2021 14:15
-
-
Save partageit/d091039f1942baed910a3f54f491056c to your computer and use it in GitHub Desktop.
Reset WebSQL database dropping every tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var db = openDatabase('myDatabase', '', 'My database description', 5 * 1024 * 1024); | |
if (reinitDb) { | |
db.changeVersion(db.version, '', function(t) { | |
t.executeSql("SELECT name FROM sqlite_master WHERE type='table' and name not like '__Webkit%'", [], function(sqlTransaction, sqlResultSet) { | |
var table, tablesNumber = sqlResultSet.rows.length; | |
console.log('DATABASE RESET MODE ENABLED'); | |
for (var i = 0; i < tablesNumber; i++) { | |
table = sqlResultSet.rows.item(i); | |
console.log('Removing table: ' + table.name); | |
sqlTransaction.executeSql('DROP TABLE ' + table.name); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment