diff options
author | stephan <stephan@noemail.net> | 2022-09-12 17:59:04 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-09-12 17:59:04 +0000 |
commit | a002cc174ffa1e440643b28b3571a60675b94a86 (patch) | |
tree | 2e489e5e4cf39b901c76792d57c84569c2f3b699 /ext/wasm/api/sqlite3-api-oo1.js | |
parent | 5360f5fcff10bb4f3ff292a2686f6cfc22a1993d (diff) | |
download | sqlite-a002cc174ffa1e440643b28b3571a60675b94a86.tar.gz sqlite-a002cc174ffa1e440643b28b3571a60675b94a86.zip |
Add sqlite3.oo1.DB.clearKvvfsStorage(). Add controls to kvvfs1.js demo to reset and query the db without requiring the dev console.
FossilOrigin-Name: d845c6c22bd5d3fffc66e0566df346d690dd8bd1fc1688e312161b1a1edcfd79
Diffstat (limited to 'ext/wasm/api/sqlite3-api-oo1.js')
-rw-r--r-- | ext/wasm/api/sqlite3-api-oo1.js | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index af179d1fe..3dfe5bfb0 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -1581,17 +1581,30 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ }/*oo1 object*/; if( self.window===self && 0!==capi.sqlite3_vfs_find('kvvfs') ){ - /* In the main window thread, add a couple of convenience proxies - for localStorage and sessionStorage DBs... */ - let klass = sqlite3.oo1.LocalStorageDb = function(){ - dbCtorHelper.call(this, 'local', 'c', 'kvvfs'); - }; - klass.prototype = DB.prototype; - - klass = sqlite3.oo1.SessionStorageDb = function(){ - dbCtorHelper.call(this, 'session', 'c', 'kvvfs'); + /* Features specific to kvvfs... */ + /** + Clears all storage used by the kvvfs DB backend, deleting any + DB(s) stored there. Its argument must be either 'session', + 'local', or ''. In the first two cases, only sessionStorage + resp. localStorage is cleared. If it's an empty string (the + default) then both are cleared. Only storage keys which match + the pattern used by kvvfs are cleared: any other client-side + data are retained. + */ + DB.clearKvvfsStorage = function(which=''){ + const prefix = 'kvvfs-'+which; + const stores = []; + if('session'===which || ''===which) stores.push(sessionStorage); + if('local'===which || ''===which) stores.push(localStorage); + stores.forEach(function(s){ + const toRm = []; + let i = 0, k; + for( i = 0; (k = s.key(i)); ++i ){ + if(k.startsWith(prefix)) toRm.push(k); + } + toRm.forEach((kk)=>s.removeItem(kk)); + }); }; - klass.prototype = DB.prototype; - } + }/* main-window-only bits */ }); |